cf.301.D. Bad Luck Island(dp + probabilities)
2 seconds
256 megabytes
standard input
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.
The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
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.
2 2 2
0.333333333333 0.333333333333 0.333333333333
2 1 2
0.150000000000 0.300000000000 0.550000000000
1 1 3
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)的更多相关文章
- CodeForces 540D Bad Luck Island (DP)
题意:一个岛上有石头,剪刀和布,规则就不用说了,问你最后只剩下每一种的概率是多少. 析:很明显的一个概率DP,用d[i][j][k]表示,石头剩下 i 个,剪刀剩下 j 个,布剩下 k 个,d[r][ ...
- CF#301 D:Bad Luck Island (概率dp)
D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...
- 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 ...
- CF 540D——Bad Luck Island——————【概率dp】
Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 【CF540D】 D. Bad Luck Island (概率DP)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- Codeforces 540 D Bad Luck Island
Discription The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp pap ...
- CF #301 E:Infinite Inversions(逆序数,树状数组)
A-Combination Lock B-School Marks C-Ice Cave D-Bad Luck Island E-Infinite Inversions E:Infini ...
随机推荐
- mongoDB在centos7上的安装
1,下载安装包 下载MongoDB的安装文件 地址:https://www.mongodb.org/downloads#production 选择Linux 64-bit legacy 版本,下载到目 ...
- UVa 1025 A Spy in the Metro(动态规划)
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...
- ejb 远程调用
1,客户端代码: package com.example.test; import java.util.Hashtable; import java.util.Properties; import j ...
- 使用Wireshark 抓取数据包
Wireshark 是一个网络封包分析软件.网络封包分析软件的功能是获取网络封包,并尽可能显示出最为详细的网络封包资料.Wireshark使用WinPCAP作为接口,直接与网卡进行数据报文交换. 一 ...
- OpenGLES入门笔记二
#import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> #import <OpenGLES/ES2/gl.h& ...
- hibernate......1、2级缓存
1.什么是缓存? 缓存是介于物理数据源与应用程序之间,是对数据库中的数据复制一份临时放在内存中的容器,其作用是为了减少应用程序对物理数据源访问的次数,从而提高了应用程序的运行性能.Hibernate在 ...
- Java关键字——instanceof
Java中可以使用instanceof关键字判断一个对象到底是哪一个类的实例 格式:对象 instance 类 返回 boolean类型 通过子类实例化的对象同时是子类和父类的实例,无论是直接声明子类 ...
- 重启nginx
在env/nginx/sbin目录下输入:nginx,即可重启
- js中的preventDefault与stopPropagation详解
本篇文章主要是对js中的preventDefault与stopPropagation进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 首先讲解一下js中preventDefault和stopP ...
- ecshop变量介绍
获得商品的信息,get_goods_info($goods_id) 获取前10销量排名,get_top10()