题目链接: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]。同理剩下的两种情况。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e2+; double dp[MAXN][MAXN][MAXN];
int main()
{
int n, m, p;
while(scanf("%d%d%d",&n,&m,&p)!=EOF)
{
memset(dp, , sizeof(dp));
dp[n][m][p] = 1.0;
for(int i = n; i>=; i--)
for(int j = m; j>=; j--)
for(int k = p; k>=; k--)
{
if(i&&j) dp[i][j-][k] += (1.0*i*j/(i*j+j*k+i*k))*dp[i][j][k];
if(j&&k) dp[i][j][k-] += (1.0*j*k/(i*j+j*k+i*k))*dp[i][j][k];
if(i&&k) dp[i-][j][k] += (1.0*i*k/(i*j+j*k+i*k))*dp[i][j][k];
} double r1 = , r2 = , r3 = ;
for(int i = ; i<=n; i++) r1 += dp[i][][];
for(int i = ; i<=m; i++) r2 += dp[][i][];
for(int i = ; i<=p; i++) r3 += dp[][][i]; printf("%.10f %.10f %.10f\n", r1,r2,r3);
}
}

最新文章

  1. CommandPattern
  2. 多项目并行开发如何做到快速切换——sublime Text3
  3. 【Cocos2d-x游戏开发】细数Cocos2d-x开发中那些常用的C++11知识
  4. SQLServer内置函数
  5. glusterFS安装维护文档
  6. codeforces Gym 100187A A. Potion of Immortality
  7. 2463: [中山市选2009]谁能赢呢?- BZOJ
  8. HTTP协议 概述
  9. doT.js 模板引擎的使用
  10. 第一个Django项目及部署到Sina App Engine
  11. if判断 和&amp;&amp;
  12. Echarts数据可视化parallel平行坐标系,开发全解+完美注释
  13. TensorFlow.org教程笔记(一)Tensorflow初上手
  14. django 实战篇之视图层
  15. zookeeper配置中心实战--solrcloud zookeeper配置中心原理及源码分析
  16. angluarjs中页面初始化的时候会出现语法{{}}在页面中问题
  17. dismiss 多个viewController
  18. Django关于设置自定义404和安装debug-toolbar的笔记
  19. @Cacheable注解式缓存不起作用的情形
  20. Redis整理

热门文章

  1. VC++动态链接库(DLL)编程深入浅出(三)
  2. mpvue上手
  3. [ACM] POJ 3233 Matrix Power Series (求矩阵A+A^2+A^3...+A^k,二分求和或者矩阵转化)
  4. WebService中获取request对象一例
  5. 【ORACLE】ORA-27102: out of memory报错的处理
  6. EMMC电路设计
  7. Battery Charging Specification 1.2 中文详解
  8. Lua学习六----------Lua流程控制
  9. 显存不够----ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[4096]
  10. erlang中通过ip和子网掩码,计算地址范围 【二进制和十进制的转换】