D. 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
 #include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
const double eps = 1e- ;
int r , s , p ;
const int M = + ;
double dp[M][M][M] ; void work ()
{
dp[r][s][p] = ;
for (int i = r ; i >= ; i --) {
for (int j = s ; j >= ; j --) {
for (int t = p ; t >= ; t --) {
if (i*j + j*t + t*i == ) continue;
if (i) dp[i - ][j][t] += dp[i][j][t] * i * t / (1.0 * (i * j + i * t + j * t)) ;
if (j) dp[i][j - ][t] += dp[i][j][t] * j * i / (1.0 * (i * j +i * t +j * t)) ;
if (t) dp[i][j][t - ] += dp[i][j][t] * t * j / (1.0 * (i * j + i * t + j * t )) ;
}
}
}
}
int main()
{
// freopen ("a.txt" , "r" , stdin ) ;
while (~ scanf ("%d%d%d" , &r , &s , &p)) {
memset (dp , , sizeof(dp)) ;
work () ;
double sum = ;
for (int i = ; i <= r ;i ++) {
if (dp[i][][] > eps) {
sum += dp[i][][] ;
}
}
printf ("%.12f " , sum );
int i ;
for (sum = ,i = ; i <= s ;i ++) {
if (dp[][i][] > eps) {
sum += dp[][i][] ;
}
}
printf ("%.12f " , sum ) ;
for (sum = , i = ; i <= p ;i ++) {
if (dp[][][i] > eps) {
sum += dp[][][i] ;
}
}
printf ("%.12f\n" , sum ) ;
}
return ;
}

Let's count the values dp[r][s][p] — the probability of the situation when r rocks, s scissors and p papers are alive. The initial probability is 1, and in order to calculate the others we should perform the transitions.

Imagine we have r rocks, s scissors and p papers. Let's find the probability of the rock killing scissors (the other probabilities are calculated in the same way). The total number of the possible pairs where one species kills the other one is rs + rp + sp, and the number of possible pairs (rock, scissors) is rs. As all meetings are equiprobable, the probability we want to find is . This is the probability with which we go the the state dp[r][s — 1][p], with the number of scissors less by one.

In the end, for example, to get the probability of the event that the rocks are alive, we should sum all values dp[i][0][0] for i from 1 to r (the same goes to the other species).

cf.301.D. Bad Luck Island(dp + probabilities)的更多相关文章

  1. CodeForces 540D Bad Luck Island (DP)

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

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

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

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

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

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

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

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

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

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

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

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

  8. Codeforces 540 D Bad Luck Island

    Discription The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp pap ...

  9. CF #301 E:Infinite Inversions(逆序数,树状数组)

    A-Combination Lock  B-School Marks   C-Ice Cave   D-Bad Luck Island   E-Infinite Inversions E:Infini ...

随机推荐

  1. Unity 依赖注入知识点

    三种依赖注入方法,构造器注入.属性注入.方法注入 可以配置Config文件,来实现不用修改代码.需要先将接口与实体关联,然后使用时会自动加载对应实体. namespace WeChatConsole ...

  2. 高性能JavaScript笔记一(加载和执行、数据访问、DOM编程)

    写在前面 好的书,可能你第一遍并不能领会里面的精魂,当再次细细品评的时候,发现领悟的又是一层新的含义 (这段时间,工作上也不会像从前一样做起来毫不费力,开始有了新的挑战,现在的老大让我既佩服又嫉妒,但 ...

  3. 收集的一些jQuery (我平常用的少的,但确实挺有效果的)

    禁用Jquery(动画)效果 jQuery.fx.off = true; 使用自己的 Bullets(这个有一丁点儿的小技巧) //这里是js代码 也就是给每个ul添加一个类名 然后给ul的子li前面 ...

  4. uC/OS-II队列(OS_q)块

    /*************************************************************************************************** ...

  5. DS18B20函数库建立实验

    1.主代码: /* 温度传感器  */#include "DS18B20.h"#include"def.h"u16 get_temp (void){    fl ...

  6. css001 Css需要的html

    Css需要的html 可以忘却的html属性和标签 1.不要用<font>来控制字体的大小和类型.(那要用什么?见第六章) 2.不要用<b>和<i>(b和i只是把字 ...

  7. ecstore小记

    主要app base 基础MVCdbeav 数据库扩展pam 登录认证setup 系统安装工具image 图片存取site 站点desktop 后台操作ectools 电商基础工具b2c 订单,商品, ...

  8. Maven打包可执行jar

    参考文献:http://blog.csdn.net/xiao__gui/article/details/47341385 方法:使用assembly插件,生成的jar包名为xxx-jar-with-d ...

  9. Ubuntu下安装了java但启动eclipse报错说没装java

    参考资料:http://blog.csdn.net/happyteafriends/article/details/8290950 一.问题 在Ubuntu下安装了java并在~/.bashrc配置了 ...

  10. Python特殊语法:filter、map、reduce、lambda [转]

    Python特殊语法:filter.map.reduce.lambda [转] python内置了一些非常有趣但非常有用的函数,充分体现了Python的语言魅力! filter(function, s ...