Hunters

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

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
题意:两个猎人比赛打猎,现在猎物有老虎和狼,猎杀老虎有X分,猎杀狼有Y分,并且其中一个猎人Alice知道同伴选择猎杀老虎的概率Q,猎杀狼的概率为(1-Q),并且如果两个人分别独自猎杀狼或者老虎,都能百分百将猎物猎杀,但如果他们选择
猎杀同一猎物,不管猎杀谁,Alice都有P的概率率先猎杀猎物,而其同伴则有(1-P)的概率猎杀猎物,求Alice的期望分数,并输出最高的期望分数(选狼还是选老虎)。
思路:概率问题,程序就是计算得到的期望公式就好了,没什么难度。期望公式
Alice选老虎的E(score)=( - Q)*X + Q*(X*P + Y*P) 
Alice选狼的   E(score)=Q*Y + ( - Q)*(Y*P + X*P)
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int N_MAX = +;
double P, Q,X,Y;
int main() {
int T;
scanf("%d",&T);
while (T--) {
scanf("%lf%lf%lf%lf", &X, &Y, &P, &Q);
double ext_1 = ( - Q)*X + Q*(X*P + Y*P);
double ext_2 = Q*Y + ( - Q)*(Y*P + X*P);
if (ext_1 > ext_2) {
printf("tiger %.4lf\n", ext_1);
}
else
printf("wolf %.4lf\n",ext_2);
}
return ;
}

最新文章

  1. *HDU1251 字典树
  2. etcd相关资料
  3. Bootstrap 表格 笔记
  4. WCF入门(10)
  5. Java 多线程Future和FutureTask
  6. 20145218 《Java程序设计》第六周学习总结
  7. Oracle_Q&amp;A_01
  8. 11gOCP 1z0-052 :2013-09-11 MGR_ROLE role........................................................A66
  9. 如何判断NSDictionary是否包含某个键
  10. 设计模式-发布订阅模式(javaScript)
  11. mysql常用命令及语法规范
  12. Centos yum 修改为阿里源以及常用的命令
  13. Vue + Element UI 实现权限管理系统 前端篇(十):动态加载菜单
  14. 常见网站CSS样式重置
  15. MacOS安装react。问题 -- npm全局包的权限问题
  16. js重定向跳转页面
  17. 第一次Scrum会议(10/13)【欢迎来怼】
  18. Winfrom控件使用
  19. 【Web前端】div层调整zindex属性无效原因分析及解决方法
  20. C语言学习笔记 (002) - C++中引用和指针的区别(转载)

热门文章

  1. iOS与JS相互传值与交互
  2. Mac下快捷键的符号所对应的按键
  3. 理解JS闭包的几个小实验
  4. Github使用技巧总结
  5. numpy的linspace使用详解
  6. 【思维题 并查集 图论】bzoj1576: [Usaco2009 Jan]安全路经Travel
  7. 关于bc中小数点length,scale,(())以及进制转换
  8. php 常用函数集合(持续更新中...)
  9. 【linux】【进程】stand alone 与 super daemon 区别
  10. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Take Your Seat