博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4438 概率 多个情况下的数学期望
阅读量:5938 次
发布时间:2019-06-19

本文共 2993 字,大约阅读时间需要 9 分钟。

Hunters

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1501    Accepted Submission(s): 1129
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
 
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
 
2012天津区域赛最水之题:

题意容易读懂,然后就是分情况求出A得分的数学期望,所谓数学期望就是在该概率下的平均得分。

现在就是两种方案,Alice要根据输入给出的数据情况选出最优方案,也就是先选老虎,还是狼。

1.A先选老虎:

   a.B也先选老虎,则得分为Q(P*X+P*Y);

   b.B选狼,则两人可以直接获得猎物,则得分为(1-Q)*X

所以1方案Alice先选老虎的得分期望是a+b;(数学期望每种情况的概率加起来要为1,这里以Bob的选择情况为分水岭,容易得出)

2.A先选狼:

   a.B先......

   b.B先.....

然后比较A和B的得分期望那个高,就选哪种方案,另外输出也给出了提示,即选择Tiger和Wolf的得分情况。

#include 
#include
using namespace std;int main(){ int T; cin>>T; while(T--){ double a,b; double x,y,p,q; cin>>x>>y>>p>>q; a=q*(p*x+p*y)+(1-q)*x; b=(1-q)*(p*x+p*y)+y*q; if(a>b) printf("tiger %.4f\n",a); else printf("wolf %.4f\n",b); } return 0;}

 

转载于:https://www.cnblogs.com/zhangmingzhao/p/7256747.html

你可能感兴趣的文章
python ORM理解、元类
查看>>
2018软工实践第一次作业
查看>>
Weekly 4
查看>>
线性表之单链表
查看>>
DP+矩阵快速幂 HDOJ 5318 The Goddess Of The Moon
查看>>
在朗沃这段时间的学习感想
查看>>
(转载)RabbitMQ消息队列应用
查看>>
【转】大型网站后台架构的演变
查看>>
几招防范Java漏洞
查看>>
『003』索引-脚本
查看>>
CH5102 Mobile Service
查看>>
C++当中的virtual继承
查看>>
手机H5显示一像素的细线
查看>>
Menu 菜单栏
查看>>
Integer跟int的区别(备份回忆)
查看>>
集合解析
查看>>
详解分布式应用程序协调服务Zookeeper
查看>>
windows下python2和python3共存
查看>>
奇幻RPG(人物构建 与 Abstract Factory模式)
查看>>
转JS技巧
查看>>