CodeForces

题目链接: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
", r1,r2,r3);
44     }
45 }
View Code
原文地址:https://www.cnblogs.com/DOLFAMINGO/p/8995363.html