CF 301div2 D. Bad Luck Island

D. Bad Luck Island

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.

题意:有三种人,人数分别为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 }

原文地址:https://www.cnblogs.com/thief-of-book/p/11827790.html

时间: 2024-10-29 21:52:07

CF 301div2 D. Bad Luck Island的相关文章

cf 540D D. Bad Luck Island 概率dp

D. 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

CF#301 D:Bad Luck Island (概率dp)

D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储剩下 i 个石头, j 个剪刀,k 个布时的概率,共dp三次: 如果石头与剪刀碰面,概率是 p1 = i*j / (i*j+j*k+k*i),这种情况下,剪刀会被石头吃掉,所以石头的数目减少1,表现出来是dp[i-1][j][k] = p1*dp[i][j][k]  (dp的3的返回值均

[Codeforces Round #301 (Div. 2) D]Bad Luck Island(概率Dp)

Description 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, t

Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP

D. Bad Luck Island 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 spe

Codeforces 540 D Bad Luck Island

Discription The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, th

CF 540D Bad Luck Island

一看就是DP题(很水的一道紫题) 设\(dp[i][j][k]\)为留下\(i\)个\(r\)族的人,死去\(j\)个\(s\)族的人,死去\(k\)个\(p\)族的人的概率(跟其他的题解有点差别,但本质相同). #include <bits/stdc++.h> using namespace std; double dp[101][101][101]; int a, b, c; int main() { scanf("%d%d%d", &a, &b, &a

Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)

一道概率dp问题. 题目链接:http://codeforces.com/contest/540/problem/D 题目大意:一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储i个石头,j个剪刀,k个布时,某物种的存活概率,共dp三次,算出三个物种分别的概率. 首先,我们需要把对应想求的物种概率初始化,这里以石头为例,那么对于i从1到r,不难理解dp[i][0][0]=

CodeForces 540D Bad Luck Island 概率dp

CodeForces 540D 应该是简单概率dp,由于写得少显得十分蠢萌 求期望逆推,求概率正推,大概是这么个意思,贴一发留恋 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define db double const int maxn=108; db dp[maxn][maxn][maxn]; int main() { int i,j,n,m,k,p; whi

Codeforces 540D Bad Luck Island - 概率+记忆化搜索

[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是随机的.到最后岛上只剩下一种生物,问这种生物分别是A,B,C的概率是多少. [题解] 其实很简单,这题,状态方程很好想.. 设dp[i][j][k]为生物A有i只,生物B有j只,生物C有k只的概率情况,显然dp的返回值应该有三个,分别是最后剩下该种生物的概率 那么我们考虑状态转移的情况. 如果A与B