zoukankan      html  css  js  c++  java
  • codeforces148D_推论题

    题目链接:http://www.codeforces.com/problemset/problem/148/D

    题意:一个袋子里有白老鼠和黑老鼠,dragon 和 princess轮流抓一只,dragon 抓了一只后会吓跑一只老鼠,princess先抓,谁先抓到白老鼠谁赢,问princess赢的概率是多少?

    思路:dp[i]表示princess第 i 回合赢了,答案就是dp[1] + dp[2] + dp[3] + ......

    假设

    princess第一回合就赢了dp[1] = w / (w + b) ;

    princess第二回合就赢了dp[2] = w * b * (b - 1) / ( (w + b) * (w + b - 1) * (w + b - 2) ) ;

    princess第三回合就赢了dp[3] = w * b * (b - 1) * (b - 2) * (b - 3) / ( (w + b) * (w + b - 1) * (w + b - 2) * (w + b - 3) * (w + b - 4) );

    。。。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <vector>
     7 #include <cmath>
     8 #include <queue>
     9 #include <set>
    10 #include <map>
    11 #define INF 0x3f3f3f3f
    12 using namespace std;
    13 typedef long long LL;
    14 
    15 double dp[1010];
    16 int main()
    17 {
    18     int w, b;
    19     scanf("%d %d", &w, &b);
    20     double res = 0;
    21     if(b == 0 && w != 0)
    22     {
    23         res = 1;
    24     }
    25     else if(w != 0 && b != 0)
    26     {
    27         dp[1] = w * 1.0 / (w + b);
    28         int j = 2, k = (int)((w + b) * 1.0 / 3);
    29         if((w + b) * 1.0 / 3 > (int)((w + b) * 1.0 / 3))
    30             k++;
    31         for(int i = b; j <= k; i -= 2, j++)
    32         {
    33             dp[j] = dp[j - 1] * i * (i - 1) * 1.0 / ((w + i - 1) * (w + i - 2));
    34         }
    35         for(int i = 1; i < j; i++)
    36             res += dp[i];
    37     }
    38     printf("%.9lf
    ", res);
    39     return 0;
    40 }
    View Code
  • 相关阅读:
    [Gamma阶段]展示博客
    [Gamma阶段]测试报告
    软工实践个人总结
    小组最终答辩
    第08组 Beta版本演示
    第08组 Beta冲刺(5/5)
    第08组 Beta冲刺(4/5)
    第08组 Beta冲刺(2/5)
    第08组 Beta冲刺(3/5)
    第08组 Beta冲刺(1/5)
  • 原文地址:https://www.cnblogs.com/luomi/p/5701511.html
Copyright © 2011-2022 走看看