• 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
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    网站访问量大 怎样优化mysql数据库
    BootStrap 模态框禁用空白处点击关闭
    常用SQL语句
    诅咒JavaScript之----ArcGIS JavaScript 点聚合 ClusterLayer
    模态框与 天地图地图控件冲突
    FXK Javascript
    从列表中或数组中随机抽取固定数量的元素组成新的数组或列表
    wangEditor
    手把手教你用vue-cli构建一个简单的路由应用
    解决eclipse端口被占用的问题
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5764083.html
Copyright © 2020-2023  润新知