A - Hunters题解
来源:互联网 发布:淘宝店主 编辑:程序博客网 时间:2024/05/16 12:42
A - Hunters
Time Limit:1000MS Memory Limit:32768KB 64bitIO Format:%I64d & %I64u
Description
Alice and Bob are the topmost hunters in the forest, so no preys canescape from them. However, they both think that its hunting skill is betterthan the other. So they need a match.
In their match, the targets are two animals, a tiger and a wolf. They both knowthat the tiger is living in the south of the forest and the wolf is living inthe north of the forest. They decide that the one who kills the tiger scores Xpoints and who kills the wolf scores Y points. If the one who kills both tigerand wolf scores X+Y points.
Before the match starts, Aliceis in the east of the forest and Bob is in the west of the forest. When thematch starts, Alice and Bob will choose one of the preys as targets. Becausethey haven't known the other's choice, maybe they choose the same target. Therewill be two situations:
(1) If they choose different targets, they both are sure of killing theirrespective targets.
(2) If they choose the same target, the probability of Alice killing the target is P, and theprobability of Bob killing it is 1-P. Then they will hunt for the other prey,also the probability of Alicekilling it is P and the probability of Bob killing it is 1-P.
But Alice knowsabout Bob. She knows that the probability of Bob choosing tiger as his firsttarget is Q, and the probability of choosing wolf is 1-Q. So that Alice can decide herfirst target to make her expected score as high as possible.
Input
The first line of input contains an integer T (1≤T≤10000), the numberof test cases.
Then T test cases follow. Each test case contains X, Y, P, Q in one line. X andY are integers and 1≤X, Y≤1000000000. P and Q are decimals and 0≤P, Q≤1, andthere are at most two digits after decimal point.
Output
For each test case, output the target Alice should choose and the highest expectedscore she can get, in one line, separated by a space. The expected score shouldbe rounded to the fourth digit after decimal point. It is guaranteed that Alice will have differentexpected 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
这是求期望值的简单数学题。代码如下:
#include"stdio.h"int main(){int T;int x,y;double p,q,d1,d2;scanf("%d",&T);while(T--){scanf("%d%d%lf%lf",&x,&y,&p,&q);d1=(1-q)*x+p*q*(x+y);d2=(1-q)*p*(x+y)+q*y;if(d1>d2){printf("tiger %.4lf\n",d1);}else{printf("wolf %.4lf\n",d2);}}return 0;}
- A - Hunters题解
- hdu44438 Hunters
- hdu4438 - Hunters
- hdu4438 Hunters
- [hdu4438]Hunters
- A.Bug.Hunters.Diary.A.Guided.Tour.Through.the.Wilds.of.Software.Security 笔记
- [HDU4438][TJ08H]Hunters
- hdu 4438 Hunters
- hdu 4438 Hunters
- HDU 4438 Hunters(模拟)
- HDU-#4438 Hunters
- HDU-4438-Hunters
- HDU 4438 Hunters
- codeforces A. Cakeminator 题解
- codeforces A. TL 题解
- codeforces A. Array题解
- codeforces 150A 题解
- 【JZOJ100019】A 题解
- 纯CSS实现箭头旋转
- 郁闷的RecipientEditTextView!!!
- 中国的高速公路和美国接轨了?
- 相位相关matlab实现
- uva 10917 Walk Through the Forest(最短路+DP路径,4级)
- A - Hunters题解
- 将txt文件中的数据批量插入到数据库中SqlBulkCopy
- ubuntu下卸载mysql
- 用win7远程桌面连接ubuntu!!
- 初窥Linux 之 数据流重定向
- WSAEventSelect模型客户端代码示例
- 跟Google学习Android开发-起始篇-保存数据
- 未来有多远
- 黑马程序员自学笔记 Java基础<五>---> 多线程