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. HDU 1535 Invitation Cards(最短路 spfa)

    题目链接: 传送门 Invitation Cards Time Limit: 5000MS     Memory Limit: 32768 K Description In the age of te ...

  2. IIS7.5

    一.发布mvc遇到的HTTP错误 403.14-Forbidden解决办法 <system.webServer>   <validationvalidateIntegratedMod ...

  3. DNS(二)之构建域名解析缓存

    域名解析缓存的必要性 在部署服务的时候,很多程序需要使用域名解析的功能,一般配置/etc/resovl.conf去指定DNS服务器的IP,但是如果程序发起的请求量较大,那么服务器就容易被DNS服务器禁 ...

  4. JavaScript中局部变量与全局变量的不同

    JavaScript中局部变量与全局变量 我们知道,JavaScript的变量是松散型的变量,也就是说,其变量只需用var声明,其赋值的类型是不限定的.比如: var person=18; perso ...

  5. SaltStack与ZeroMQ(二)

    SaltStack与ZeroMQ SaltStack底层是基于ZeroMQ进行高效的网络通信. ZeroMQ简介 ØMQ (也拼写作ZeroMQ,0MQ或ZMQ)是一个为可伸缩的分布式或并发应用程序设 ...

  6. sql 分页的两种写法

    string Strsql = string.Format(@"select ee.DOCUMENTNO,ee.APPLICANTNAME,ee.COMPANY,ee.REQUESTTIME ...

  7. JQuery------.load()从服务器获取数据并加载到某个类的方法

    注意:需要在../Content/asf.txt路径下加入文件 html <button class="Btn">按钮</button> js 参数意义: ...

  8. pyqt2_官网教程

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

  9. Java——按钮组件:JButton

    import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; impor ...

  10. 关于软件工程结对编程作业 PairProject : Elevator Scheduler(电梯调度算法的实现与测试)的总结

    1)结对编程队友 1106xxxx 张扬 1106xxxx 杨军 其中,此项目的编程实现主要由前者完成. 2)关于结对编程 结对编程的优点: 最直接的一点:在结对编程中,由于有另一个人在你身边和你配合 ...