【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 ...
随机推荐
- Spring4笔记11--SSH整合2--SpringWeb
SSH 框架整合技术: 2. Spring 在 Web 项目中的使用(建立在Spring与Hibernate整合的基础上): 在 Web 项目中使用 Spring 框架,首先要解决在 Servlet ...
- SQL 存储过程分页
CREATE PROC p_Team_GetTemaList @pageindex INT , @pagesize INT , @keywords VARCHAR(200) , --模糊查询 名称 标 ...
- easyui表单提交验证form
方式一,不需要考虑jquery.easyui.min.js版本 <script> $(function () { //针对 设置 novalidate:true $('.validateb ...
- Jenkins+Ant+TestNG+Testlink自动化构建集成
这段时间折腾自动化测试,之前都是在Eclipse工程里面手工执行自动化测试脚本,调用Testlink API执行测试用例,目前搭建Jenkins自动化构建测试的方式,实现持续构建,执行自动化测试. 硬 ...
- mysql测试工具 -> mysqlslap
一.简介 mysqlslap是mysql自带的基准测试工具 优点:查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比 ...
- align="absmiddle" 的意义
align=absmiddle表示图像的中间与同一行中最大元素的中间对齐 AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐. AbsMiddle 图像的中间与同一行中最大元素的中间对 ...
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- Java集合类 课后练习
1.Pg235--2分别向Set集合以及List集合中添加“A”,“a” , "c" , "C" , "a" 5个元素,观察重复值“a”能 ...
- python中发送邮件各种问题
其实问题主要集中的QQ企业邮箱中,特别坑爹...代码如下: from email.mime.multipart import MIMEMultipart from email.mime.base im ...
- 第一个iOS程序:Hello iOS
今天我们来创建第一个iOS程序:Hello iOS!不需要写任何代码就能实现: