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

Sample test(s)
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个人。三类人中最后会剩下一种人的概率分别是多少。
定义dp[i][j][k]表示剩下出石头的i个,出剪刀的j个,出布的k个的概率。dp[i][j][k]=dp[i+1][j][k]*pi+dp[i][j+1][k]*pj+dp[i][j][k+1]*pk。
#include<bits/stdc++.h>
using namespace std;
double dp[110][110][110];
int main(){
int r,s,p;
double sum;
while(scanf("%d%d%d",&r,&s,&p)!=EOF){
memset(dp,0,sizeof(dp));
dp[r][s][p]=1.0;
for(int i=r;i>=1;i--){
for(int j=s;j>=1;j--){
for(int k=p;k>=1;k--){
sum=i*j+j*k+i*k*1.0;
dp[i-1][j][k]+=dp[i][j][k]*(i*k*1.0/sum);
dp[i][j-1][k]+=dp[i][j][k]*(i*j*1.0/sum);
dp[i][j][k-1]+=dp[i][j][k]*(j*k*1.0/sum);
}
}
}
double ans1,ans2,ans3;
ans1=ans2=ans3=0;
for(int i=r;i>=1;i--){
for(int j=s;j>=0;j--){
ans1+=dp[i][j][0];
}
}
for(int j=s;j>=1;j--){
for(int k=p;k>=0;k--){
ans2+=dp[0][j][k];
}
}
for(int i=r;i>=0;i--){
for(int k=p;k>=1;k--){
ans3+=dp[i][0][k];
}
}
printf("%.10f %.10f %.10f\n",ans1,ans2,ans3);
}
return 0;
}

  

CF 540D——Bad Luck Island——————【概率dp】的更多相关文章

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

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

  2. 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/pr ...

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

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

  4. CF 540D Bad Luck Island

    一看就是DP题(很水的一道紫题) 设\(dp[i][j][k]\)为留下\(i\)个\(r\)族的人,死去\(j\)个\(s\)族的人,死去\(k\)个\(p\)族的人的概率(跟其他的题解有点差别,但 ...

  5. cf540D. Bad Luck Island(概率dp)

    题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存 ...

  6. CodeForces - 540D Bad Luck Island —— 求概率

    题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...

  7. CodeForces 540D Bad Luck Island (DP)

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

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

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

  9. CF 148D Bag of mice 概率dp 难度:0

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. c++语言的学习笔记代码与笔记注释《函数部分》

    具体的笔记以注释的形式写在代码内,每个知识点用函数的形式表现. #include <iostream>; #include<cmath> const double PI=3.1 ...

  2. 接口和抽象类有什么区别(Java基础)

    接口可以多实现 Java中抽象类只能单继承 接口   相对于类来说    可以实现多个接口 抽象相对于 类来说 只能单一继承 一个类只能继承一个抽象类,但可以实现多个接口. 抽象类中可以包含抽象方法和 ...

  3. js数据类型基础

    一.数据类型 数据类型包括:基本数据类型和引用数据类型 基本数据类型指的是简单的数据段,引用数据类型指的是有多个值构成的对象. 当我们把变量赋值给一个变量时,解析器首先要确认的就是这个值是基本类型值还 ...

  4. t-sql read xlsx

    How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility To read an ...

  5. 【三支火把】--- shell脚本中变量的类型及作用域

    一直对shell脚本有一种特殊的感觉,因此花了一段时间学习,本人擅长C语言编程,深受C语言荼毒,在学习其他任何类似于编程语言的东东的时候,都会不自觉的与C进行对比,因此对于shell中的变量的作用域一 ...

  6. window.open 设置高和宽无效

    当设置_self属性时,再设置宽和高就不管用,这个宽高会继承父窗口的宽高! window.open("url","_self","width=100, ...

  7. Gym - 101572G Galactic Collegiate Programming Contest 小根堆(set)

    题目传送门 题目大意: n个人,m次提交,每次提交都代表某支队伍做出一题,并且给出罚时,让你输出每次提交后,编号为1的队伍的排名. 思路: 首先处理ac和罚时,由于罚时最大1000,最多有1e5次,要 ...

  8. tarjan算法,一个关于 图的联通性的神奇算法

    一.算法简介 Tarjan 算法一种由Robert Tarjan提出的求解有向图强连通分量的算法,它能做到线性时间的复杂度. 我们定义: 如果两个顶点可以相互通达,则称两个顶点强连通(strongly ...

  9. struts1学习

    转载:https://blog.csdn.net/toyouheart/article/details/4509466

  10. linux 网卡配置文件详解2018-03-07

    转自:https://www.cnblogs.com/ienino/p/7717092.html 配置文件位置:/etc/sysconfig/network-scripts/ifcfg-eth0 1. ...