어제 새벽 1시에 열렸던 매치.. 흑.. 통한의 리서밋 덕분에.. 점수가 폭락했다.. ㅠ_ㅠ
이번엔 나름 솔루션을 빨리 떠올려서 210점대에 서밋 완료했는데..
한참후에 초기화 안한걸 발견.. 리서밋.. -_-;; 덕분에 또 div2로 떨어졌다..;;;;
500점은 상당히 까다로웠고.. 1000점은 열어보지도 않음..
Level1 - PrimeSoccer
Problem Statement
You are watching a soccer match, and you wonder what the probability is that at least one of the two teams will score a prime number of goals. The game lasts 90 minutes, and to simplify the analysis, we will split the match into five-minute intervals. The first interval is the first five minutes, the second interval is the next five minutes, and so on. During each interval, there is a skillOfTeamA percent probability that team A will score a goal, and a skillOfTeamB percent probability that teamB will score a goal. Assume that each team will score at most one goal within each interval. Return the probability that at least one team will have a prime number as its final score.
Definition
Class:
PrimeSoccer
Method:
getProbability
Parameters:
int, int
Returns:
double
Method signature:
double getProbability(int skillOfTeamA, int skillOfTeamB)
(be sure your method is public)
Notes
-
The returned value must be accurate to within a relative or absolute value of 1E-9.
-
A prime number is a number that has exactly two divisors, 1 and itself. Note that 0 and 1 are not prime.
Constraints
-
skillOfTeamA will be between 0 and 100, inclusive.
-
skillOfTeamB will be between 0 and 100, inclusive.
Examples
0)
50
50
Returns: 0.5265618908306351
1)
100
100
Returns: 0.0
Both teams will score a goal in each interval, so the final result will be 18 to 18.
2)
12
89
Returns: 0.6772047168840167
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
축구 경기가 90분이라고 할때 시작부터 5분마다 양 팀이 골을 넣을 수 있는 확률이 percentage로 주어진다.. 각 5분 간격에 최대 넣을 수 있는 골은 최대 1골이라고 가정.. (즉, 최대 넣을 수 있는 골은 18골이 됨) 이때, 양 팀중 최소 한팀이라도 넣은 골의 수가 prime일 확률 구하기..
간단하게 DP로 풀었다.
dp[i][j] = i번째 period에 j골을 넣을 확률이라고 하면..
dp[i][j] = dp[i-1][j] * (이번에 골을 못넣을 확률) + dp[i-1][j-1] * (이번에 골을 넣을 확률)
이 된다.
그리고 나서 inclusion exclusion principle에 의해서..
A팀이 prime 골을 기록할 확률 + B팀이 prime 골을 기록할 확률에서 두 팀 모두 prime 골을 기록할 확률을 빼면 된다.
1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <vector>
5 #include <string>
6 using namespace std;
7
8 int is_prime(int u)
9 {
10 int i;
11 if (u < 2)
12 return 0;
13 for (i = 2; i < u; i++) {
14 if (u % i == 0)
15 return 0;
16 }
17 return 1;
18 }
19
20 class PrimeSoccer {
21 public:
22
23 double getProbability(int A, int B)
24 {
25 int i, j;
26 double dp[20][20], dp2[20][20];
27 double sum;
28 memset(dp, 0, sizeof(dp));
29 memset(dp2, 0, sizeof(dp2));
30 dp[0][0] = 1.0;
31 for (i = 1; i <= 18 ; i++) {
32 dp[i][0] = dp[i-1][0] * (1.0 - ((double)A / 100.0));
33 for (j = 1; j <= 18; j++) {
34 dp[i][j] = dp[i-1][j] * (1.0 - ((double)A / 100.0));
35 dp[i][j] += dp[i-1][j-1] * (double)A / 100.0;
36 }
37 }
38 dp2[0][0] = 1.0;
39 for (i = 1; i <= 18 ; i++) {
40 dp2[i][0] = dp2[i-1][0] * (1.0 - ((double)B / 100.0));
41 for (j = 1; j <= 18; j++) {
42 dp2[i][j] = dp2[i-1][j] * (1.0 - ((double)B / 100.0));
43 dp2[i][j] += dp2[i-1][j-1] * (double)B / 100.0;
44 }
45 }
46 sum = 0.0;
47 for (i = 2; i <= 18; i++) {
48 if (is_prime(i)) {
49 sum += dp[18][i];
50 sum += dp2[18][i];
51 }
52 }
53 for (i = 2; i <= 18; i++) {
54 for (j = 2; j <= 18; j++) {
55 if (is_prime(i) && is_prime(j)) {
56 sum -= dp[18][i] * dp2[18][j];
57 }
58 }
59 }
60 printf("%lf\n", sum);
61 return sum;
62 }
63
64 };
Level2 - CavePassage
Problem Statement
Several travelers are standing at the entrance of a dark cave. The travelers must all pass through the cave and stand together at the exit. Unfortunately, a variety of circumstances can make it impossible for them to all pass through the cave together at the same time. Therefore, they may have to take turns going through the cave in smaller groups. There is only one map though, and it is impossible to navigate the cave without it, so whenever a group of travelers is inside the cave, one member of that group must be holding the map. When a group of travelers walks through the cave, either from the entrance or the exit, they must traverse an old bridge to get to the other side of the cave. The entire group inside the cave must cross the bridge together at the same time. The bridge cannot hold more than bridgeStrength kilograms, or it will collapse. You are given a vector <int> travelersWeights, where the i-th element is the weight of the i-th traveler in kilograms. Travelers may walk through the cave alone. Although, when travelers walk through the cave in a group of two or more, each traveler must trust at least one of the other travelers in the group. You are given a vector <string> trustTable, where the j-th character of the i-th element is 'Y' if traveler i trusts traveler j, and 'N' otherwise. Note that the trust relation is not necessarily symmetric. Travelers walk at different speeds, but when they go through the cave, they must stick together and walk at the same speed. Therefore, when a group of travelers walks through the cave, they must walk at the speed of the slowest traveler in the group. You are given a vector <int> travelersTimes, where the i-th element is the amount of time it takes the i-th traveler to walk through the cave in any direction. Return the minimal total time required for all the travelers to end up together at the exit of the cave. If it is impossible, return -1 instead.
Definition
Class:
CavePassage
Method:
minimalTime
Parameters:
vector <int>, vector <int>, vector <string>, int
Returns:
int
Method signature:
int minimalTime(vector <int> travelersWeights, vector <int> travelersTimes, vector <string> trustTable, int bridgeStrength)
(be sure your method is public)
Constraints
-
travelersWeights will contain between 1 and 13 elements, inclusive.
-
Each element of travelersWeights will be between 1 and 1000, inclusive.
-
travelersTimes will contain the same number of elements as travelersWeights.
-
Each element of travelersTimes will be between 1 and 1000, inclusive.
-
trustTable will contain the same number of elements as travelersWeights.
-
Each element of trustTable will contain exactly n characters, where n is the number of elements in trustTable.
-
Each element of trustTable will contain only uppercase letters 'Y' and 'N'.
-
The i-th character of the i-th element of trustTable will always be 'Y'.
-
bridgeStrength will be between 1 and 5000, inclusive.
Examples
0)
{ 1, 1, 1 }
{ 2, 3, 4 }
{ "YYY", "YYY", "YYY" }
2
Returns: 9
The travelers can achieve the goal as follows. First, traveler 0 and traveler 2 go through the cave together. It normally takes 2 time units for traveler 0 to go through the cave, and it takes 4 time units for traveler 2. Since they are traveling together in a group, they must walk at the speed of the slower traveler. So, after 4 time units, both travelers are at the exit. Then, traveler 0 takes the map and goes back through the cave to the entrance. This time, it only takes 2 time units because he is alone. Finally, traveler 0 and traveler 1 go through the cave together in 3 time units and all the travelers end up together at the exit. The total time is 4 + 2 + 3 = 9.
1)
{ 1, 1, 1 }
{ 2, 3, 4 }
{ "YYY", "YYY", "NYY" }
2
Returns: 10
Here things become a little bit more complicated, because traveler 2 doesn't trust traveler 0.
2)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
여행객들이 동굴을 지나가야한다.. 지도는 단 하나이고 지도 없이는 동굴을 지나갈 수 없다. 여러명이 그룹을 지어 동굴을 통과하게 된다.. 동굴 안에 다리가 있는데.. 특정 무게 이상이 한번에 지나갈 수 없다.. 사람들끼리 서로 trust하는 사람이 있다.. 같이 가는 그룹중에 최소 한명이라도 trust하는 사람이 있어야.. 같은 그룹으로 갈 수 있다.. 사람마다 걷는 속도가 있고.. 같은 그룹일 경우 가장 느린사람 속도에 맞춰서 지나게 된다.. 등등..
이문제는 여러모로 유명한 문제인데 한때 구글 입사 면접문제로도 알려진 UVa 10037 - Bridge 문제를 여러가지 제약조건을 두어서 더 복잡하게 꼬아놨다.. 젠장!!!
to be updated..
Level3 - WorkersOnPlane
Problem Statement
You have recently bought a field containing gold and silver, and you want to hire some workers to gather the treasure and build beautiful things with it. The field is divided into square cells of equal size. You are given a vector <string> field, where the j-th character of the i-th element is the content of the cell at row i, column j. A period ('.') represents grass, an uppercase 'X' represents rocks, and uppercase 'G' and 'S' represent gold and silver, respectively. You have also built special workplace cells for your workers, each denoted by an uppercase 'W'. Each worker must be assigned exactly one workplace, one gold cell and one silver cell. None of these three cells can be assigned to any of the other workers. Each worker will be transporting gold and silver from his cells to his workspace, and for efficiency reasons, you do not want workers to carry anything for more than K meters. This means every worker's workplace must be at most K meters away from his gold cell and at most K meters away from his silver cell. Distance is measured as follows. From each cell, a worker can only move left, right, up or down to an adjacent cell (if one exists). The distance between two consecutive cells is one meter. Workers are only allowed to walk on grass when moving between their cells. Return the largest number of workers you can hire while meeting these requirements.
Definition
Class:
WorkersOnPlane
Method:
howMany
Parameters:
vector <string>, int
Returns:
int
Method signature:
int howMany(vector <string> field, int K)
(be sure your method is public)
Constraints
-
field will contain between 1 and 30 elements, inclusive.
-
Each element of field will contain between 1 and 30 characters, inclusive.
-
Each element of field will contain the same number of characters.
-
Each character in each element of field will be a period ('.'), an uppercase 'X', an uppercase 'G', an uppercase 'S' or an uppercase 'W'.
-
K will be between 1 and 1000, inclusive.
Examples
0)
{ "GG..",
"XX..",
"..W.",
"..W.",
"SS.." }
10
Returns: 1
We can hire only one worker, because the gold mine in the top left corner can't be reached from any of the workplaces.
3)
{"G.XXX.S",
"G..WW.S"}
11
Returns: 0
If we hire a worker for the left workplace, he won't be able to reach any of the silver mines. Similarly, if we hire a worker for the right workplace, he won't be able to reach gold mines. So we can't hire anybody.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.