• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
HDU 4438 Hunters (数学,概率计算)

题意:猎人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;
}

 

posted on 2016-08-12 10:47  dwtfukgv  阅读(224)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3