zoukankan      html  css  js  c++  java
  • 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
    ",ans1,ans2,ans3);
    }
  • 相关阅读:
    SqlLiteHelper:基于C#的SqlLite数据库访问基类
    SQL注入专题整理帖
    SQLite数据库查询优化
    php mysql与mysqli 区别
    PHPCMS V9模板制作常用变量表
    实用正则手机和邮箱
    windows2003+iis6.0+php(fastcgi)5.3+wincache+memcached
    ajax 写法
    php防注入,表单提交值转义
    IE6下的两个兼容问题调试
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4470269.html
Copyright © 2011-2022 走看看