【CF540D】 D. Bad Luck Island (概率DP)
D. Bad Luck Islandtime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputPrint 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.
Examplesinput2 2 2output0.333333333333 0.333333333333 0.333333333333input2 1 2output0.150000000000 0.300000000000 0.550000000000input1 1 3output0.057142857143 0.657142857143 0.285714285714
【题意】
有r个石头、s个剪刀、p个布,每一次两个人随机碰上,输的人死掉,问只剩下每一种的概率。
【分析】
还是一样的配方。。
f[i][j][k]表示没了i个石头,j个剪刀,k个布的情况下剩下。。。的概率。
这个也是要移项一下的。
三个都做一遍就好了。
【一开始概率求错了,求概率的话做好是用组合数算方案吧不容易错。。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 110 double f[][Maxn][Maxn][Maxn]; double C(int x)
{
return 1.0*x*(x-)/;
} int main()
{
int r,s,p;
scanf("%d%d%d",&r,&s,&p);
for(int i=r;i>=;i--)//rocks
for(int j=s;j>=;j--)//scissors
for(int k=p;k>=;k--)//papers
{
int N=r+s+p-i-j-k;if(N==) continue;
double PI=1.0/C(N),PP=C(r-i)+C(s-j)+C(p-k),
R=1.0*(r-i),S=1.0*(s-j),P=1.0*(p-k); if(j==s&&k==p) f[][i][j][k]=,f[][i][j][k]=f[][i][j][k]=;
else if(i==r&&k==p) f[][i][j][k]=,f[][i][j][k]=f[][i][j][k]=;
else if(i==r&&j==s) f[][i][j][k]=,f[][i][j][k]=f[][i][j][k]=;
else
{
f[][i][j][k]=(R*S*PI*f[][i][j+][k]+R*P*PI*f[][i+][j][k]+S*P*PI*f[][i][j][k+])/(1.0-PP*PI);
f[][i][j][k]=(R*S*PI*f[][i][j+][k]+R*P*PI*f[][i+][j][k]+S*P*PI*f[][i][j][k+])/(1.0-PP*PI);
f[][i][j][k]=(R*S*PI*f[][i][j+][k]+R*P*PI*f[][i+][j][k]+S*P*PI*f[][i][j][k+])/(1.0-PP*PI);
}
}
printf("%.9lf %.9lf %.9lf\n",f[][][][],f[][][][],f[][][][]);
return ;
}
2017-04-21 21:28:51
【CF540D】 D. Bad Luck Island (概率DP)的更多相关文章
- 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 ...
- cf540D. Bad Luck Island(概率dp)
题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存 ...
- codeforces 540D Bad Luck Island (概率DP)
题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...
- CF540D Bad Luck Island(期望dp)
传送门 解题思路 比较容易的一道期望\(dp\),设\(f[i][j][k]\)表示石头\(i\)个,剪刀\(j\)个,步子\(l\)个.然后转移的时候用组合数算一下就好了. 代码 #include& ...
- Codeforces 540D Bad Luck Island - 概率+记忆化搜索
[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...
- 题解 CF540D 【Bad Luck Island】
既然没有大佬写题解那本蒟蒻就厚颜无耻地写(水)一(经)下(验)吧 题目要求算出个种人单独留下的存活率 因为n,m,p的范围极小, 那么就可以方便地设3位dp状态dp[i][j][k]表示剩余i个石头, ...
- CF#301 D:Bad Luck Island (概率dp)
D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...
- 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 ...
随机推荐
- C. Connect Three(构造)
题目链接:http://codeforces.com/contest/1087/problem/C 题目大意:给你三个点的坐标,让你用尽可能少的方块,让这三个点连起来. 具体思路: 我们先对这三个点进 ...
- Html 使用技巧 -- 设置display属性可以使div隐藏后释放占用的页面空间
div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visibility: none;" document.getElemen ...
- Docker Compose practice
Docker Compose 什么是 Docker-Compose? Compose 可以让用户在集群中部署分布式应用.简单的说,Docker Compose 属于一个"应用层"的 ...
- OpenStack 监控解决方案
正如你们看到的那样,到目前为止(OpenStack Kilo),OpenStack自己的监控组件Telemetry并不是完美, 获取的监控数据以及制作出来的图表有时候让人匪夷所思,因其重点并不是监控而 ...
- 八、springboot整合redis
整合Redis 一. 注解方式实现添加缓存 1.在pom.xml加入依赖 <!-- 配置使用redis启动器 --> <dependency> <groupId>o ...
- 数据库-mysql函数
一:MySQL中提供了许多内置函数 CHAR_LENGTH(str) 返回值为字符串str 的长度,长度的单位为字符.一个多字节字符算作一个单字符. 对于一个包含五个二字节字符集, LENGTH()返 ...
- python网络编程--线程锁(互斥锁Mutex)
一:为什么需要线程锁 一个进程下可以启动多个线程,多个线程共享父进程的内存空间,也就意味着每个线程可以访问同一份数据,此时,如果2个线程同时要修改同一份数据,会出现什么状况? 很简单,假设你有A,B两 ...
- windows下同时安装python2和python3
之前学习的时候使用2.7比较多. 想练习3.7的时候,两个版本兼容的问题,苦恼了几天. 查了一下资料,发现了一个很好的方法.记录一下,也做一个分享. 本篇内容主要讲一下,在同一台电脑上如何同时安装Py ...
- thinkphp模型实例化
方法一 方法二
- WordPress“无法将上传的文件移动至wp-content/uploads/”的解决办法
WordPress“无法将上传的文件移动至wp-content/uploads/”的问题在有些配置不完善的虚拟主机或服务器中会碰到,一般会出现以下症状:1.无论是从文章编辑页面还是媒体库页面都无法上传 ...