CodeForces - 540D Bad Luck Island - Find Probabilities

Question link: 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

 

code show as below:

 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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325305799&siteId=291194637