[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, 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.

Solution

题意:岛上有三种居民,石头r个,剪刀s个,布p个,他们会以相等的概率相遇,输的一方就被杀死,问最后剩下的是每种居民的概率各是多少

用f[i][j][k]表示表示还剩i个石头、j个剪刀、k个布这种状态出现的概率

f[i][j][k]=

f[i+1][j][k]*((i+1)*k)/((i+1)*j+(i+1)*k+j*k)

+f[i][j+1][k]*((j+1)*i)/(i*(j+1)+i*k+(j+1)*k)

+f[i][j][k+1]*((k+1)*j)/(i*j+i*(k+1)+j*(k+1))

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int r,s,p;
double f[107][107][107],ans[3];
int main()
{
    scanf("%d%d%d",&r,&s,&p);
    f[r][s][p]=1;
    for(int i=r;i>=0;i--)
    {
        for(int j=s;j>=0;j--)
        {
            for(int k=p;k>=0;k--)
            {
                if(j&&k)f[i][j][k]+=f[i+1][j][k]*((i+1)*k)/((i+1)*j+(i+1)*k+j*k);
                if(i&&k)f[i][j][k]+=f[i][j+1][k]*((j+1)*i)/(i*(j+1)+i*k+(j+1)*k);
                if(i&&j)f[i][j][k]+=f[i][j][k+1]*((k+1)*j)/(i*j+i*(k+1)+j*(k+1));
            }
        }
    }
    for(int i=1;i<=r;i++)
    for(int j=1;j<=s;j++)
    ans[0]+=f[i][j][0];

    for(int i=1;i<=s;i++)
    for(int j=1;j<=p;j++)
    ans[1]+=f[0][i][j];

    for(int i=1;i<=r;i++)
    for(int j=1;j<=p;j++)
    ans[2]+=f[i][0][j];

    printf("%.12lf %.12lf %.12lf\n",ans[0],ans[1],ans[2]);
    return 0;
} 
时间: 2024-10-24 16:32:39

[Codeforces Round #301 (Div. 2) D]Bad Luck Island(概率Dp)的相关文章

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 Round #293 (Div. 2) D. Ilya and Escalator (概率DP)

dp[i][j]表示第i秒电梯进去的人数为j时的概率.由于概率比较好求,而且这里的样本是有限个.所以可以先求出概率,然后用公式转化成期望. #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <

Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                               D. Painting The Wall User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not

Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp

E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she w

Codeforces Round #301 (Div. 2) -- (A,B,C,D)

题目传送:Codeforces Round #301 (Div. 2) A. Combination Lock 水题,求最小移动次数,简单贪心一下即可 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #i

DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

题目传送门 1 /* 2 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 3 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两点相邻, 4 那么要不就是踩一脚就破了或者踩一脚走开再走回来踩一脚破了:3. 普通的搜索看是否能到达, 5 若能还是要讨论终点踩几脚的问题:) 6 DFS 耗时大,险些超时,可以用BFS来做 7 */ 8 #include <cstdio> 9 #include <algorit

贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

题目传送门 1 /* 2 贪心水题:累加到目标数字的距离,两头找取最小值 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 char s[MAXN],

贪心 Codeforces Round #301 (Div. 2) B. School Marks

题目传送门 1 /* 2 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 3 num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 using na

CodeForces Round #301 Div.2

今天唯一的成果就是把上次几个人一起开房打的那场cf补一下. A. Combination Lock 此等水题看一眼样例加上那个配图我就明白题意了,可是手抽没有注释掉freopen,WA了一发. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 1000 + 10; 5 6 char s1[maxn], s2[maxn]; 7 8 int main() 9 { 10 int n; cin >>