【CF540D】 D. Bad Luck Island (概率DP)
D. Bad Luck Islandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe 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.
InputThe single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
OutputPrint 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.
Examplesinput2 2 2output0.333333333333 0.333333333333 0.333333333333input2 1 2output0.150000000000 0.300000000000 0.550000000000input1 1 3output0.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 }
2017-04-21 21:28:51