Subject description:
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 r, s 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
Copy
2 2 2
Output
Copy
0.333333333333 0.333333333333 0.333333333333
Input
Copy
2 1 2
Output
Copy
0.150000000000 0.300000000000 0.550000000000
Input
Copy
1 1 3
Output
Copy
0.057142857143 0.657142857143 0.285714285714
Ideas:
This question is just look at the time feel good magic ah, be sure to use the knowledge to good probability tall, but my math has been lost over, it can only be skipped. Once you know the law better understand the magical feel, ah ~ magic probability dp.
Definition of DP [i] [j] [k] is the i-th species remaining rock, scissors remaining j-th, k th probability happens cloth left. dp beginning [r] [s] [p] = 1, now consider a state transition.
When a pair of scissors will be less of it? It encountered a stone, the probability of this happening is it? \ (\ {C_S FRAC * C_r ^ ^. 1. 1} + {R & lt C_ {P} S ^ 2} + \) , at least one fabric Similarly it? It encountered a pair of scissors, the probability of it? \ (\ FRAC {C_p ^. 1 * ^. 1 C_S} {C_ {R & lt + S + P} ^ 2} \) , at least one probability stones \ (\ frac {C_p ^ 1 * C_r ^ 1} {C_ { } S + P + R & lt ^ 2} \) , then the state transition equation is
\ [Sum = source + Q + clear \]
\[dp[i-1][j][k]+=dp[i][j][k]*\frac{C_s^1*C_r^1}{sum}\]
\[dp[i][j-1][k]+=dp[i][j][k]*\frac{C_p^1*C_r^1}{C_{sum}^2}\]
\[dp[i][j][k-1]+=dp[i][j][k]*\frac{C_p^1*C_s^1}{C_{sum}^2}\]
Recursive to start from scratch.
Statistics last answer when statistics dp [i] [j] [0] This answer, because the answer to this outcome has been set, there is only one species
Code:
#include <iostream>
#include <iomanip>
#define max_n 105
using namespace std;
int r,s,p;
double dp[max_n][max_n][max_n];
int main()
{
cin >> r >> s >> p;
dp[r][s][p] = 1.0;
for(int i = r;i>0;i--)
{
for(int j = s;j>0;j--)
{
for(int k = p;k>0;k--)
{
double sum = i*j+i*k+j*k;
dp[i-1][j][k] += dp[i][j][k]*(double)(i*k)/sum;
dp[i][j-1][k] += dp[i][j][k]*(double)(i*j)/sum;
dp[i][j][k-1] += dp[i][j][k]*(double)(j*k)/sum;
}
}
}
double ans1 = 0;
double ans2 = 0;
double ans3 = 0;
for(int i = 0;i<=100;i++)
{
for(int j = 0;j<=100;j++)
{
ans1 += dp[i][j][0];
ans2 += dp[0][i][j];
ans3 += dp[i][0][j];
}
}
cout.setf(ios_base::fixed,ios_base::floatfield);
cout << setprecision(12) << ans1 << " " << ans2 << " " << ans3 << endl;
return 0;
}