标签:details center 遇到 sep time std relative number a long
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.
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.
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.
题意:有三种人,人数分别为r(石头),s(剪刀),p(布),每队遇到的概率是相等的,根据熟悉正常的游戏规则,问只剩一种人的概率
思路:DP,可以参照这个大佬写的,总结的很好,此时的状态等于上一次的状态*(转到这一状态的概率)
1 #include<bits/stdc++.h> 2 using namespace std; 3 double dp[1100][110][110] = { 0 }; 4 double u(int r, int s, int p,int x,int y) 5 { 6 double d = r * s + s * p + r * p; 7 double ss = x * y; 8 double ans = ss / d; 9 return ans; 10 } 11 int main() 12 { 13 ios::sync_with_stdio(0); 14 int r, s, p; 15 cin >> r >> s >> p; 16 dp[r][s][p] = 1; 17 for (int i = r; i >= 0; i--) 18 { 19 for(int j=s;j>=0;j--) 20 for (int k = p; k >= 0; k--) 21 { 22 if (i == r && j == s && k == p) 23 continue; 24 if (i != 0) 25 dp[i][j][k] += dp[i][j+1][k]*u(i,j+1,k,i,j+1); 26 if (j != 0) 27 dp[i][j][k] += dp[i][j][k + 1]*u(i,j,k+1,j,k+1); 28 if (k != 0) 29 dp[i][j][k] += dp[i + 1][j][k]*u(i+1,j,k,k,i+1); 30 } 31 } 32 double s1 = 0, s2 = 0, s3 = 0; 33 for (int i = 1; i <= r; i++) 34 s1 += dp[i][0][0]; 35 for (int i = 1; i <= s; i++) 36 s2 += dp[0][i][0]; 37 for (int i = 1; i <= p; i++) 38 s3 += dp[0][0][i]; 39 40 printf("%.12lf\n", s1); 41 printf("%.12lf\n", s2); 42 printf("%.12lf\n", s3); 43 return 0; 44 }
标签:details center 遇到 sep time std relative number a long
原文地址:https://www.cnblogs.com/thief-of-book/p/11827790.html