题目大意:Alice and Bob两个人去打猎,北山有虎,南山有狼,现在两个人有两种选择,当一个人去一个方向的时候打到的概率为1,否则Alice获得猎物概率为p,而他知道Bob要去打老虎的概率是q,问Alice能够赢得的最高分是多少?
解题思路:只有两种情况下,对于Alice而言,她要去打老虎,则为Bob选择打老虎Alice得到猎物的概率为:p*q。Bob不选择打老虎Alice得到猎物的概率为:(1-q)*(x*1.0/(x+y),综上两种情况Alice选择打老虎的得分即为(p*q+(1-q)*(x*1.0/(x+y)))*(x+y)。如果Alice选择打狼,则同理可得(p*(1-q)+q*(y*1.0/(x+y)))*(x+y)。最后比较她两种选择最高得分输出即可,详见code。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4438
code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int x,y,t;
double p,q,ans1,ans2;
int main(){
//freopen("input.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d%d%lf%lf",&x,&y,&p,&q);
ans1=(p*q+(1-q)*(x*1.0/(x+y)))*(x+y);
ans2=(p*(1-q)+q*(y*1.0/(x+y)))*(x+y);
if(ans1>ans2) printf("tiger %.4f\n",ans1);
else printf("wolf %.4f\n",ans2);
}
return 0;
}