HDU-4438-Hunters

来源:互联网 发布:webpack this windows 编辑:程序博客网 时间:2024/05/17 06:25

Hunters

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1107    Accepted Submission(s): 850


Problem Description
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
32 1 0.5 0.52 1 0 17 7 0.32 0.16
 

Sample Output
tiger 1.7500wolf 1.0000tiger 6.5968
 

Source
2012 Asia Tianjin Regional Contest
 



绝对水题!!

就是两个期望值!!

不过陷在浮点数陷阱里错了一次!!

以后注意浮点数不能直接相等!!


AC代码:

#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){int T;double x, y, p, q;scanf("%d", &T);while(T--){scanf("%lf %lf %lf %lf", &x, &y, &p, &q);double ans1 = q*(x*p+y*p) + (1-q)*x, ans2 = (1-q)*(x*p+y*p) + q*y;if(ans1 > ans2)printf("tiger %.4lf\n", ans1);else printf("wolf %.4lf\n", ans2);}return 0;} 



AC代码(之前没注意浮点数陷阱错了一次):

#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define max(a,b) (a)>(b)?(a):(b)using namespace std;int main(){    int T, x, y;    double p, q;    scanf("%d", &T);    while(T--)    {        scanf("%d %d %lf %lf", &x, &y, &p, &q);        double ans1=q*(x*p+y*p) + (1-q)*x, ans2=(1-q)*(x*p+y*p) + q*y;        double ans = max(ans1, ans2);        if(ans-ans1<1e-6)printf("tiger ");  //不能写ans==ans1,会产生浮点数误差!!         else printf("wolf ");        printf("%.4lf\n", ans);    }    return 0;} 



1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 才学瑜伽教培上课紧张怎么办 瑜伽馆不给退费怎么办 脚运动后酸痛该怎么办 婴儿误吞拉链头怎么办 肠功能蠕动慢便秘怎么办 胃肠型和蠕动波怎么办 胃不蠕动了怎么办偏方 喂母乳母亲奶头裂开怎么办 给宝宝吃奶被吃到奶头裂开怎么办 宝宝吃奶奶头裂开了怎么办 小孩吃奶奶头裂开了怎么办 站久坐久腰酸痛怎么办 孕39周胎儿头小怎么办 怀孕腰两侧长肉怎么办 怀孕四个月半月吃点就饱怎么办啊 怀孕四个月睡眠不好怎么办 二胎七个月肚子太大怎么办 上火牙疼牙龈肿怎么办 孕30周乳房胀痛怎么办 怀孕长妊娠纹了怎么办 坐久了肚子胀疼怎么办 怀孕后胖的太快怎么办 怀孕牙齿全坏了怎么办 怀孕脸胖了好多怎么办 孕晚期不爱吃肉怎么办 怀孕期间胖了怎么办啊 孕期长得太胖怎么办 狗吃马肉脸肿了怎么办 狗过敏了脸肿了怎么办 孕初期外阴很痒怎么办 怀孕了吃了田鸡怎么办 孕妇睡眠质量差怎么办吃什么 39周2天了还不生怎么办 孕中期体重猛长怎么办 4个半月胎位不正怎么办 41周不产生宫缩怎么办 生完孩子胎盘没有脱落怎么办 39周还是臀位怎么办 怀孕7个月胎位不正怎么办 怀孕六个多月胎位不正怎么办 怀孕七个月了胎位不正怎么办