Hunters HDU - 4438 (概率期望)

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.

Input
The 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.
Output
For 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

题意:

给定杀死老虎的分数是X,杀死狼的分数是Y

对方一开始去杀老虎的概率是Q,杀狼的概率则是1-Q

如果一开始双方选取的不同目标,就可以直接杀了得分

如果一开始选取了相同目标,自己能杀死的概率是P

问应该先杀哪个?自己的最大得分期望

分析:

我们只需要求出先杀老虎的得分和先杀狼的得分一比较输出大的即可

如果杀老虎

有两种情况对方1-Q的概率去杀狼了,所以杀死老虎的X分因此此时得分期望(1-Q)* X

如果对方Q的概率去杀老虎,此时双方都杀老虎,那么自己能得分的概率是P,然后一起再去杀狼,此时自己能得分的概率仍然是P,所以此时得分期望为Q*(P*X+P*Y)

扫描二维码关注公众号,回复: 2913667 查看本文章

所以先杀老虎的得分总期望为

(1-Q) * X+Q * (P * X+P * Y)

如果先杀狼

如果对方以Q的概率去杀老虎了,那么杀死狼得到Y分,此时得分期望为Q * Y

如果对方以(1-Q)的概率先杀狼,那么自己有P的概率得分,然后一起去杀老虎,有P的概率得分,此时得分期望为(1-Q)* (P * Y + P * X)

所以先杀狼的得分总期望为

Q * Y+(1-Q)* (P * Y+P * X)

比较两个值即可

code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int X,Y;
    double P,Q;
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%lf%lf",&X,&Y,&P,&Q);
        double ans1 = (1-Q)*X+Q*(P*X+P*Y);
        double ans2 = Q*Y+(1-Q)*(P*Y+P*X);
        if(ans1 > ans2) printf("tiger %.4f\n",ans1);
        else printf("wolf %.4f\n",ans2);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/codeswarrior/article/details/81747034