题目链接:https://vjudge.net/contest/226823#problem/D

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.

Examples

Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714

题意:

有r个石头,s个剪刀,p个布。每次都随机挑出,问:最后只剩下石头、剪刀、布的概率分别是多少?

题解:

1.设dp[i][j][k]为:剩余i个石头,j个剪刀,k个布的概率。

2.可知:如果选到的两个是同类型,那么这一轮是无意义的,且对结果毫无影响,所以可忽略这种情况,只需考虑两者不同的情况。

3.假设当前还剩余i个石头,j个剪刀,k个布,那么下一轮抽到石头和剪刀的概率为(不需考虑同类型的):(i*j)/(i*j+i*k+j*k),而此种情况的结果为[i][j-1][k],所以dp[i][j-1][k] += (i*j)/(i*j+i*k+j*k)*dp[i][j][k]。同理剩下的两种情况。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e2+; double dp[MAXN][MAXN][MAXN];
int main()
{
int n, m, p;
while(scanf("%d%d%d",&n,&m,&p)!=EOF)
{
memset(dp, , sizeof(dp));
dp[n][m][p] = 1.0;
for(int i = n; i>=; i--)
for(int j = m; j>=; j--)
for(int k = p; k>=; k--)
{
if(i&&j) dp[i][j-][k] += (1.0*i*j/(i*j+j*k+i*k))*dp[i][j][k];
if(j&&k) dp[i][j][k-] += (1.0*j*k/(i*j+j*k+i*k))*dp[i][j][k];
if(i&&k) dp[i-][j][k] += (1.0*i*k/(i*j+j*k+i*k))*dp[i][j][k];
} double r1 = , r2 = , r3 = ;
for(int i = ; i<=n; i++) r1 += dp[i][][];
for(int i = ; i<=m; i++) r2 += dp[][i][];
for(int i = ; i<=p; i++) r3 += dp[][][i]; printf("%.10f %.10f %.10f\n", r1,r2,r3);
}
}

CodeForces - 540D Bad Luck Island —— 求概率的更多相关文章

  1. CF 540D——Bad Luck Island——————【概率dp】

    Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. Codeforces B. Bad Luck Island(概率dp)

    题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

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

    [题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...

  4. codeforces 540D Bad Luck Island (概率DP)

    题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...

  5. Codeforces 540D Bad Luck Island

    http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...

  6. 540D - Bad Luck Island(概率DP)

    原题链接:http://codeforces.com/problemset/problem/540/D 题意:给你石头.剪刀.布的数量,它们之间的石头能干掉剪刀,剪刀能干掉布,布能干掉石头,问最后石头 ...

  7. CodeForces 540D Bad Luck Island (DP)

    题意:一个岛上有石头,剪刀和布,规则就不用说了,问你最后只剩下每一种的概率是多少. 析:很明显的一个概率DP,用d[i][j][k]表示,石头剩下 i 个,剪刀剩下 j 个,布剩下 k 个,d[r][ ...

  8. 【CF540D】 D. Bad Luck Island (概率DP)

    D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

    D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...

随机推荐

  1. nginx 按天生成日志

    nginx日志access.log error.log按天生成存储,定时删除日志 logrotate https://linux.cn/article-4126-1.html http://blog. ...

  2. 过滤器Filter_03_多个Filter的执行顺序

    过滤器Filter_03_多个Filter的执行顺序 学习了:https://www.cnblogs.com/HigginCui/p/5772514.html 按照在web.xml中的顺序进行filt ...

  3. linux中xargs用法

    参数代换: xargs xargs 是在做什么的呢?就以字面上的意义来看, x 是加减乘除的乘号,args 则是 arguments (参数) 的意思,所以说,这个玩意儿就是在产生某个命令的参数的意思 ...

  4. Linux下快速安装Mysql及使用

    1.安装 查看有没有安装过: yum list installed mysql* rpm -qa | grep mysql* 查看有没有安装包: yum list mysql* 安装mysql客户端: ...

  5. [Python] SQLBuilder 演示样例代码

    用Python写一个SQLBuilder.Java版能够从 http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQLBuilder.htm 看到. 附 ...

  6. linux 安装jdk和tomcat

    安装jdk 下载相关jdk .rpm包,如:jdk-8u31-linux-i586.rpm 解压:#rpm -ivh jdk-8u31-linux-i586.rpm 配置环境变量:#vi  /etc/ ...

  7. jquery代码小片段

    1. 使用jQuery来切换样式表 //找出你希望切换的媒体类型(media-type),然后把href设置成新的样式表. $(‘link[media="screen"]‘).at ...

  8. 缷载vs2015后项目不能加载问题

    当加载项目时出现MSBuildToolsPath is not specified for the ToolsVersion "14.0" defined at "HKE ...

  9. springMVC --@RequestParam注解(后台控制器获取參数)

    在SpringMVC后台控制层获取參数的方式主要有两种,一种是request.getParameter("name"),第二种是用注解@RequestParam直接获取. 1.获取 ...

  10. 38: 立方根getCubeRoot

    题目描述:计算一个数字的立方根,不使用库函数 •接口说明 原型:public static double getCubeRoot(double input) 输入:double 待求解参数 返回值:d ...