您的位置:首页 > 其它

HDU 4438 Hunters (数学,概率计算)

2016-08-12 10:47 447 查看
题意:猎人A和B要进行一场比赛。现在有两个猎物老虎和狼,打死老虎可以得X分,打死狼可以得Y分。现在有两种情况:

(1)如果A与B的预定目标不同,那么他们都将猎到预定的目标。

(2)如果A与B的预定目标相同,A杀死目标的概率为P,B杀死这个目标的概率为1-P。接着他们将猎取第二只猎物,概率同上。

现在A知道B选择老虎作为他的首目标的概率为Q,B选狼作为首目标的概率为1-Q。所以A必须选择他的首目标,来使得他的期望分数最高。

析:分情况讨论么,首先选Tiger,再选Wolf,看看哪个大,就选哪个,比如先选Tiger,那么B有Q的概率也选Tiger,并且A打中的概率是P,

打完Tiger,再打Wolf,再加上,B打Wolf的期望,那么总起来的期望就是 P * Q * (X+Y) + (1-Q) * X。

同理也计算先打Wolf的期望。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
int T;  cin >> T;
while(T--){
double x, y, p, q;
cin >> x >> y >> p >> q;
double ans1 = p * q * (y + x) + (1 - q) * x;
double ans2 = q * y + p * (1 - q) * (x + y);
double ans = max(ans1, ans2);
if(ans1 > ans2)  printf("tiger ");
else  printf("wolf ");
printf("%.4f\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: