题目链接:https://vjudge.net/contest/226823#problem/D

The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.

Input

The single line contains three integers rs and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.

Output

Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.

Examples

Input
2 2 2

Output
0.333333333333 0.333333333333 0.333333333333

Input
2 1 2

Output
0.150000000000 0.300000000000 0.550000000000

Input
1 1 3

Output
0.057142857143 0.657142857143 0.285714285714

题意:

有r个石头,s个剪刀,p个布。每次都随机挑出,问:最后只剩下石头、剪刀、布的概率分别是多少?

题解:

1.设dp[i][j][k]为:剩余i个石头,j个剪刀,k个布的概率。

2.可知:如果选到的两个是同类型,那么这一轮是无意义的,且对结果毫无影响,所以可忽略这种情况,只需考虑两者不同的情况。

3.假设当前还剩余i个石头,j个剪刀,k个布,那么下一轮抽到石头和剪刀的概率为(不需考虑同类型的):(i*j)/(i*j+i*k+j*k),而此种情况的结果为[i][j-1][k],所以dp[i][j-1][k] += (i*j)/(i*j+i*k+j*k)*dp[i][j][k]。同理剩下的两种情况。

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <cstdlib>
 6 #include <string>
 7 #include <vector>
 8 #include <map>
 9 #include <set>
10 #include <queue>
11 #include <sstream>
12 #include <algorithm>
13 using namespace std;
14 typedef long long LL;
15 const double eps = 1e-8;
16 const int INF = 2e9;
17 const LL LNF = 9e18;
18 const int MOD = 1e9+7;
19 const int MAXN = 1e2+10;
20
21 double dp[MAXN][MAXN][MAXN];
22 int main()
23 {
24     int n, m, p;
25     while(scanf("%d%d%d",&n,&m,&p)!=EOF)
26     {
27         memset(dp, 0, sizeof(dp));
28         dp[n][m][p] = 1.0;
29         for(int i = n; i>=0; i--)
30         for(int j = m; j>=0; j--)
31         for(int k = p; k>=0; k--)
32         {
33             if(i&&j) dp[i][j-1][k] += (1.0*i*j/(i*j+j*k+i*k))*dp[i][j][k];
34             if(j&&k) dp[i][j][k-1] += (1.0*j*k/(i*j+j*k+i*k))*dp[i][j][k];
35             if(i&&k) dp[i-1][j][k] += (1.0*i*k/(i*j+j*k+i*k))*dp[i][j][k];
36         }
37
38         double r1 = 0, r2 = 0, r3 = 0;
39         for(int i = 1; i<=n; i++) r1 += dp[i][0][0];
40         for(int i = 1; i<=m; i++) r2 += dp[0][i][0];
41         for(int i = 1; i<=p; i++) r3 += dp[0][0][i];
42
43         printf("%.10f %.10f %.10f\n", r1,r2,r3);
44     }
45 }

View Code

转载于:https://www.cnblogs.com/DOLFAMINGO/p/8995363.html

CodeForces - 540D Bad Luck Island —— 求概率相关推荐

  1. codeforces 540D Bad Luck Island (概率DP)

    题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 三个点在同一个半圆的概率_【国际数学竞赛】列方程求概率

    在国际数学竞赛中概率的考察往往也是古典概型和几何概型,但有些题目却找不到样本空间,只有事件的交错与转化,看着很是复杂,这里就介绍一种方法--通过事件间的关系列出方程组求出概率值.下面通过2017年AM ...

  4. Codeforces 167B Wizards and Huge Prize(概率dp)

    题意: n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率 分析: 状态好确定,d ...

  5. 【概率论与数理统计】猴博士 笔记 p15-16 一、二维连续型求概率

    一维连续型求概率 题型如下: 解题步骤如下: 其实就是求积分 举例1的例子: 例2: 解: 例3: 解: 注意:要把Y变为X计算,且要分类讨论y是否大于0. 例4: 解: 去掉max和min的方法: ...

  6. 20171207_MATLAB求概率

    20171207_MATLAB求概率 1. p = normspec([0,inf],0,1)  注:直接求解出正态分布中部分面积的概率. 比如:正态分布的均值是0,方差是1,求解出随机变量 X 从0 ...

  7. Check the difficulty of problems (概率dp求概率)

    Check the difficulty of problems POJ - 2151 大致题意: m个问题,t个队伍,要求冠军队伍至少解决n个问题,给出每个队伍解决每个问题的概率 求每一个队至少解决 ...

  8. 概率论与数理统计【二】随机事件与概率(2) - 常用求概率公式与例题两道

    本节为概率论与数理统计复习笔记的第二节,随机事件与概率(2),主要包括:加法公式.减法公式.条件概率公式.乘法公式.全概率公式.贝叶斯公式以及两道例题. 1.常用的求概率公式 1.加法公式 P(A∪B ...

  9. Codeforces 148D:Bag of mice 概率DP

    Bag of mice 题目链接: http://www.codeforces.com/problemset/problem/148/D 题意: 公主和龙在玩抓老鼠的游戏,在一个包里有一些白色老鼠和一 ...

最新文章

  1. 不用sqlDataSet如何从后台数据库中读取数据
  2. MySQL数学函数简明总结
  3. 超融合架构下的数据中心
  4. 金融风控--申请评分卡模型--特征工程(特征分箱,WOE编码) 标签: 金融特征分箱-WOE编码 2017-07-16 21:26 4086人阅读 评论(2) 收藏 举报 分类: 金融风
  5. Java对象、List集合、Map和JSON格式数据的互转(谷歌的gson-2.2.4.jar包)
  6. 机器学习之生成学习算法
  7. docker 镜像选择_为什么选择Docker?
  8. caffeine 读操作源码走读 为什么读这么快
  9. activex控件方法和事件
  10. VB.NET Crystal Reports 水晶报表 自定义工具栏
  11. mac终端 install_Mac常用终端命令
  12. 将数组转换为IntPtr
  13. 养老院智能健康手环开发/功能/特点/结构/原理
  14. 给图片添加指示箭头或者选中效果
  15. 用 HLS m3u8 及FFMPEG搭建视频点播平台
  16. 已知华氏温度f c语言,编程题:已知两种温度的换算公式C=(5/9)(F-32),试编写一个程序输入华氏度F,输出摄氏度。...
  17. vipkid和vipjr比较,哪个更适合小升初学习?
  18. 西雅图“货拉拉”融资$750万,“货运Uber”会成为下一个风口吗?
  19. Linux服务器之间使用scp免密传输文件
  20. 天津铸源宝利缘系统成立仪式在津召开

热门文章

  1. navicat for mysql 数据库备份与还原
  2. mysql int类型的长度值
  3. BZOJ-1034 泡泡堂
  4. HTML/CSS/Javascript代码在线压缩、格式化(美化)工具
  5. SharePoint GridView的使用2——DataSourceView的使用
  6. Selenium UI 举例 getCssValue
  7. shell循环结构之while循环
  8. easyui动态显示和隐藏表头
  9. 【干货分享】流程DEMO-事务呈批表
  10. android学习者优秀网址推荐