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. gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能

    今天vim出现:“gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能” 解决办法: 修改你的.vimrc,增加下面的一行: set directory=.,$TEMP "默 ...

  2. 数据结构2 静态区间第K大/第K小

    给定数组$A[1...N]$, 区间$[L,R]$中第$K$大/小的数的指将$A[L...R]$中的数从大到小/从小到大排序后的第$K$个. "静态"指的是不带修改. 这个问题有多 ...

  3. JavaScript 单线程相关

    众所周知,Javascript是单线程执行的,这也就是说:JavaScript在同一个时间上只能处理一件事.他不像C,Java等这些多线程的,可以开不同的线程去同时处理多件事情. 那么为什么别的语言都 ...

  4. 【Beta版本】冲刺-Day7

    队伍:606notconnected 会议时间:12月15日 目录 一.行与思 二.站立式会议图片 三.燃尽图 四.代码Check-in 一.行与思 张斯巍(433) 今日进展:修改界面,应用图标 明 ...

  5. hdu 1863 - 畅通工程(MST)

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. oneM2M启动Release 3标准化,华为引领物联网技术布局

    http://developer.huawei.com/cn/ict/news/cn/2016/06/onem2m [韩国,首尔,2016年6月] 国际权威的物联网组织oneM2M召开第23次技术全会 ...

  7. String 类相关知识

    1.常用方法 1)判断字符串是否为空 public boolean isEmpty()2)获取字符串长度 public int length()3)截取子子串 public String substr ...

  8. MyEclipse快捷键大全(绝对全)

    存盘 Ctrl+s(肯定知道) 注释代码 Ctrl+/ 取消注释 Ctrl+\(Eclipse3已经都合并到Ctrl+/了) 代码辅助 Alt+/ 快速修复 Ctrl+1 代码格式化 Ctrl+Shi ...

  9. python学习笔记-(五)字符串&字典

    1.字符串操作 >>> name = ("my name is cc")#首字母大写 >>> print(name.capitalize()) ...

  10. pyqt2_官网教程

    https://pythonspot.com/en/pyqt4/ Articles You can find a collection of PyQT articles below. Applicat ...