Hunters(期望,数学) HDU - 4438
Alice and Bob are the topmost hunters in the forest, so no preys can escape from them. However, they both think that its hunting skill is better than the other. So they need a match.
In their match, the targets are two animals, a tiger and a wolf. They both know that the tiger is living in the south of the forest and the wolf is living in the north of the forest. They decide that the one who kills the tiger scores X points and who kills the wolf scores Y points. If the one who kills both tiger and wolf scores X+Y points.
Before the match starts, Alice is in the east of the forest and Bob is in the west of the forest. When the match starts, Alice and Bob will choose one of the preys as targets. Because they haven't known the other's choice, maybe they choose the same target. There will be two situations:
(1) If they choose different targets, they both are sure of killing their respective targets.
(2) If they choose the same target, the probability of Alice killing the target is P, and the probability of Bob killing it is 1-P. Then they will hunt for the other prey, also the probability of Alice killing it is P and the probability of Bob killing it is 1-P.
But Alice knows about Bob. She knows that the probability of Bob choosing tiger as his first target is Q, and the probability of choosing wolf is 1-Q. So that Alice can decide her first target to make her expected score as high as possible.
In their match, the targets are two animals, a tiger and a wolf. They both know that the tiger is living in the south of the forest and the wolf is living in the north of the forest. They decide that the one who kills the tiger scores X points and who kills the wolf scores Y points. If the one who kills both tiger and wolf scores X+Y points.
Before the match starts, Alice is in the east of the forest and Bob is in the west of the forest. When the match starts, Alice and Bob will choose one of the preys as targets. Because they haven't known the other's choice, maybe they choose the same target. There will be two situations:
(1) If they choose different targets, they both are sure of killing their respective targets.
(2) If they choose the same target, the probability of Alice killing the target is P, and the probability of Bob killing it is 1-P. Then they will hunt for the other prey, also the probability of Alice killing it is P and the probability of Bob killing it is 1-P.
But Alice knows about Bob. She knows that the probability of Bob choosing tiger as his first target is Q, and the probability of choosing wolf is 1-Q. So that Alice can decide her first target to make her expected score as high as possible.
InputThe first line of input contains an integer T (1≤T≤10000), the number of test cases.
Then T test cases follow. Each test case contains X, Y, P, Q in one line. X and Y are integers and 1≤X, Y≤1000000000. P and Q are decimals and 0≤P, Q≤1, and there are at most two digits after decimal point.
OutputFor each test case, output the target Alice should choose and the highest expected score she can get, in one line, separated by a space. The expected score should be rounded to the fourth digit after decimal point. It is guaranteed that Alice will have different expected score between choosing tiger and wolf.Sample Input
3 2 1 0.5 0.5 2 1 0 1 7 7 0.32 0.16
Sample Output
tiger 1.7500 wolf 1.0000 tiger 6.5968
题意:较好理解
AC代码:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<set> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 const int maxn = 2e3+10; 9 #define LL long long 10 #define INF 0x3f3f3f3f 11 int T; 12 int x,y; 13 double p,q; 14 double pos1,pos2; 15 16 int main(){ 17 scanf("%d",&T); 18 while(T--){ 19 scanf("%d%d%lf%lf",&x,&y,&p,&q); 20 pos1=(1-q)*x+q*(p*y+p*x); 21 pos2=(1-q)*(p*y+p*x)+y*q; 22 if(pos1>pos2) printf("tiger %.4f\n",pos1); 23 else printf("wolf %.4f\n",pos2); 24 } 25 26 27 return 0; 28 } 29 30 /* 31 3 32 2 1 0.5 0.5 33 2 1 0 1 34 7 7 0.32 0.16 35 */
有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!