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. WCF寄宿控制台.WindowsService.WinFrom.WebAPI寄宿控制台和windows服务

    先建立wcf类库.会默认生成一些试用代码.如下: public class Service1 { public string GetData(int value) { return string.Fo ...

  2. (原创)BZOJ 2038 小Z的袜子(hose) 莫队入门题+分块

    I - 小Z的袜子(hose) 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命…… 具体来说,小Z ...

  3. loj#6229. 这是一道简单的数学题 (??反演+杜教筛)

    题目链接 题意:给定\(n\le 10^9\),求:\(F(n)=\sum_{i=1}^n\sum_{j=1}^i\frac{\mathrm{lcm}(i,j)}{\mathrm{gcd}(i,j)} ...

  4. 模仿 spring IOC Annotation版自动装配

    spring 有两大核心 IOC和AOP.  IOC (inversion of control) 译为 控制反转,也可以称为 依赖注入 ; AOP(Aspect Oriented Programmi ...

  5. 13.Convert BST to Greater Tree(将树转为更大树)

    Level:   Easy 题目描述: Given a Binary Search Tree (BST), convert it to a Greater Tree such that every k ...

  6. 基础线程机制--Executor线程池框架

    基础线程机制 Executor线程池框架 1.引入Executor的原因 (1)new Thread()的缺点 ​  每次new Thread()耗费性能 ​  调用new Thread()创建的线程 ...

  7. 架构师 AI 技术

    架构师是大忽悠吗?阿里技术大牛告诉你真相! - huangshulang1234的博客 - CSDN博客https://blog.csdn.net/huangshulang1234/article/d ...

  8. IDEA 一些 莫名其妙的错误....解决办法...

    1.  如果 一直 update indices......... windows : 删除 c 盘 用户目录下 .IntelliJIdea2017.3/system/caches  目录 ..... ...

  9. 奇妙的 clip-path 几何图形

    CSS 新属性 clip-path,意味裁剪路径的意思,让我们可以很便捷的生成各种几何图形. clip-path 通过定义特殊的路径,实现我们想要的图形.而这个路径,正是 SVG 中的 path . ...

  10. sharepoint_study_13

    描述: 解决: 1.修改了密码和账户,找到对应的应用程序池,修改用户名和密码,重启iis. 2.站点上安装的产品(如:工作流)启动需要用户名和密码,找到对应的服务,修改用户名和密码并重启该服务.