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. C#和Javascript的try…catch…finally的一点差别

    C#中规定:如果程序的控制流进入了一个带finally块的try语句,那么finally语句块始终会被执行 例子: class Program { static void Main(string[] ...

  2. type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object

    今天在进行代码检查的时候出现下面的异常: type parameters of <T>T cannot be determined; no unique maximal instance ...

  3. C#6.0特性笔记

    Visual Studio 2015的C#6.0,今天无意中看这个视频,怕忘记其中的特性,故此进行记录. public class Point { //Getter专属自动属性 public int ...

  4. 对WEB标准以及W3C的理解与认识

    按照习惯的理解,这两个概念似乎都是指的一个东西(就是咱们在这个版里讨论的这些个"高深理论“^_^).但我认为,事实上从技术的角度上讲,这两个事物几乎没有任何相关性.web标准简而言之就是将页 ...

  5. linux修改ip地址的方法

    1. 临时设置ip地址 ifconfig eth0 IP地址 (网络掩码和网关如果不设置就使用默认0) 这种方法只是临时修改,重启网卡或服务器又会还原 2.使用vi编辑器设置 1122.www.qix ...

  6. LightOj1089(求点包含几个线段 + 线段树)

    题目链接 题意:n( n <= 50000 ) 个线段,q ( q <= 50000) 个点,问每个点在几个线段上 线段端点的和询问的点的值都很大,所以必须离散化 第一种解法:先把所有的线 ...

  7. BPEL 实例教程

    http://www.oracle.com/technetwork/cn/articles/matjaz-bpel1-090722-zhs.html BPEL 实例教程 作者:Matjaz Juric ...

  8. for 循环的关键字 break和continue

    for(int i=0;i<100;i++){ if(i==50){ continue:// 跳出当前循环,执行下面的循环,就是说,当i=50的时候,跳出循环,从i=51开始继续循环 //业务逻 ...

  9. centos nc命令安装

    yum install nc.x86_64 nc命令的参数 参数 作用-i 设置数据报传送时间间隔-l 以服务器方式运行-k 重复接收并处理某个端口上的所有连接,必须与-l选项一起使用-n 使用ip地 ...

  10. AspectJ基础学习之三HelloWorld(转载)

    AspectJ基础学习之三HelloWorld(转载) 一.创建项目 我们将project命名为:aspectjDemo.然后我们新建2个package:com.aspectj.demo.aspect ...