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

D. Bad Luck Island

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/540/problem/D

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.

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.

Sample Input

2 2 2

 

Sample Output

0.333333333333 0.333333333333 0.333333333333

 

HINT

 

题意

有个地方有三种人,分别是石头,剪刀,步

每天都会有俩不同种族的人出来,然互石头会杀死剪刀,剪刀会杀死步,步会干掉石头

然后问你,在最后,每个种族活到最后的概率是多少

题解:

概率dp,dp[i][j][k]表示,剩下人数为i,j,k的概率,转移方程:

double tmp=(i+j+k)*(i+j+k-1)/2-(i*(i-1)/2)-j*(j-1)/2-k*(k-1)/2;
//总共有多少种选择方法
if (j>0&&i>0) dp[i][j-1][k]+=dp[i][j][k]*i*j/tmp;
//选择石头剪刀的概率
if (j>0&&k>0) dp[i][j][k-1]+=dp[i][j][k]*j*k/tmp;
//选择剪刀布的概率
if (i>0&&k>0) dp[i-1][j][k]+=dp[i][j][k]*k*i/tmp;
//选择布和石头的概率

水DP = =

代码:

 

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
/*

inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
*/
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************


double dp[110][110][110];

int main()
{
    int r,s,p;
    cin>>r>>s>>p;
    dp[r][s][p]=1;
    double ans1=0,ans2=0,ans3=0;
    for(int i=r;i>=0;i--)
    {
        for(int j=s;j>=0;j--)
        {
            for(int k=p;k>=0;k--)
            {
                double tmp=(i+j+k)*(i+j+k-1)/2-(i*(i-1)/2)-j*(j-1)/2-k*(k-1)/2;
                if (j>0&&i>0)
                    dp[i][j-1][k]+=dp[i][j][k]*i*j/tmp;
                if (j>0&&k>0)
                    dp[i][j][k-1]+=dp[i][j][k]*j*k/tmp;
                if (i>0&&k>0)
                    dp[i-1][j][k]+=dp[i][j][k]*k*i/tmp;
            }
        }
    }
    for(int i=r;i>=0;i--)
        ans1+=dp[i][0][0];
    for(int j=s;j>=0;j--)
        ans2+=dp[0][j][0];
    for(int k=p;k>=0;k--)
        ans3+=dp[0][0][k];
    printf("%.10f %.10f %.10f\n",ans1,ans2,ans3);
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值