【CF540D】 D. Bad Luck Island (概率DP)

D. Bad Luck Island
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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个布,每一次两个人随机碰上,输的人死掉,问只剩下每一种的概率。

 

【分析】

  还是一样的配方。。

  f[i][j][k]表示没了i个石头,j个剪刀,k个布的情况下剩下。。。的概率。

  这个也是要移项一下的。

  三个都做一遍就好了。

  【一开始概率求错了,求概率的话做好是用组合数算方案吧不容易错。。

 

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 #define Maxn 110
 8 
 9 double f[3][Maxn][Maxn][Maxn];
10 
11 double C(int x)
12 {
13     return 1.0*x*(x-1)/2;
14 }
15 
16 int main()
17 {
18     int r,s,p;
19     scanf("%d%d%d",&r,&s,&p);
20     for(int i=r;i>=0;i--)//rocks
21      for(int j=s;j>=0;j--)//scissors
22       for(int k=p;k>=0;k--)//papers
23       {
24           int N=r+s+p-i-j-k;if(N==0) continue;
25           double PI=1.0/C(N),PP=C(r-i)+C(s-j)+C(p-k),
26                  R=1.0*(r-i),S=1.0*(s-j),P=1.0*(p-k);
27           
28           if(j==s&&k==p) f[0][i][j][k]=1,f[1][i][j][k]=f[2][i][j][k]=0;
29           else if(i==r&&k==p) f[1][i][j][k]=1,f[2][i][j][k]=f[0][i][j][k]=0;
30           else if(i==r&&j==s) f[2][i][j][k]=1,f[0][i][j][k]=f[1][i][j][k]=0;
31           else
32           {
33               f[0][i][j][k]=(R*S*PI*f[0][i][j+1][k]+R*P*PI*f[0][i+1][j][k]+S*P*PI*f[0][i][j][k+1])/(1.0-PP*PI);
34               f[1][i][j][k]=(R*S*PI*f[1][i][j+1][k]+R*P*PI*f[1][i+1][j][k]+S*P*PI*f[1][i][j][k+1])/(1.0-PP*PI);
35               f[2][i][j][k]=(R*S*PI*f[2][i][j+1][k]+R*P*PI*f[2][i+1][j][k]+S*P*PI*f[2][i][j][k+1])/(1.0-PP*PI);
36           }
37       }
38     printf("%.9lf %.9lf %.9lf\n",f[0][0][0][0],f[1][0][0][0],f[2][0][0][0]);
39     return 0;
40 }
View Code

 

2017-04-21 21:28:51

转载于:https://www.cnblogs.com/Konjakmoyu/p/6746117.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值