CF 540D——Bad Luck Island——————【概率dp】
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 题目大意:在玩猜拳游戏,只会出石头的r个人,只会出剪刀的s个人,只会出布的p个人。三类人中最后会剩下一种人的概率分别是多少。
定义dp[i][j][k]表示剩下出石头的i个,出剪刀的j个,出布的k个的概率。dp[i][j][k]=dp[i+1][j][k]*pi+dp[i][j+1][k]*pj+dp[i][j][k+1]*pk。
#include<bits/stdc++.h>
using namespace std;
double dp[110][110][110];
int main(){
int r,s,p;
double sum;
while(scanf("%d%d%d",&r,&s,&p)!=EOF){
memset(dp,0,sizeof(dp));
dp[r][s][p]=1.0;
for(int i=r;i>=1;i--){
for(int j=s;j>=1;j--){
for(int k=p;k>=1;k--){
sum=i*j+j*k+i*k*1.0;
dp[i-1][j][k]+=dp[i][j][k]*(i*k*1.0/sum);
dp[i][j-1][k]+=dp[i][j][k]*(i*j*1.0/sum);
dp[i][j][k-1]+=dp[i][j][k]*(j*k*1.0/sum);
}
}
}
double ans1,ans2,ans3;
ans1=ans2=ans3=0;
for(int i=r;i>=1;i--){
for(int j=s;j>=0;j--){
ans1+=dp[i][j][0];
}
}
for(int j=s;j>=1;j--){
for(int k=p;k>=0;k--){
ans2+=dp[0][j][k];
}
}
for(int i=r;i>=0;i--){
for(int k=p;k>=1;k--){
ans3+=dp[i][0][k];
}
}
printf("%.10f %.10f %.10f\n",ans1,ans2,ans3);
}
return 0;
}
CF 540D——Bad Luck Island——————【概率dp】的更多相关文章
- codeforces 540D Bad Luck Island (概率DP)
题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...
- 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 ...
- Codeforces 540D Bad Luck Island - 概率+记忆化搜索
[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...
- CF 540D Bad Luck Island
一看就是DP题(很水的一道紫题) 设\(dp[i][j][k]\)为留下\(i\)个\(r\)族的人,死去\(j\)个\(s\)族的人,死去\(k\)个\(p\)族的人的概率(跟其他的题解有点差别,但 ...
- cf540D. Bad Luck Island(概率dp)
题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存 ...
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- CodeForces 540D Bad Luck Island (DP)
题意:一个岛上有石头,剪刀和布,规则就不用说了,问你最后只剩下每一种的概率是多少. 析:很明显的一个概率DP,用d[i][j][k]表示,石头剩下 i 个,剪刀剩下 j 个,布剩下 k 个,d[r][ ...
- 540D - Bad Luck Island(概率DP)
原题链接:http://codeforces.com/problemset/problem/540/D 题意:给你石头.剪刀.布的数量,它们之间的石头能干掉剪刀,剪刀能干掉布,布能干掉石头,问最后石头 ...
- CF 148D Bag of mice 概率dp 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- bat 操作数据库(附加,分离,删除,还原)
BAT代码: @echo off Title DataBase Color 0A :caozuo echo. echo ═══════════════════════════════════════ ...
- 在ubuntu 14.04 编译android 2.3.1 错误解决办法
首先必须降低gcc版本: sudo apt-get install gcc-4.4sudo apt-get install g++-4.4sudo rm -rf /usr/bin/gcc /usr/b ...
- Mysql union
union简单来说就是多表链接,主要是用于(模糊)查询,全库搜索 多表搜索需要先将需要查询的表用union连接,然后在每一个union后面添加上相同的where条件 菜鸟教程
- window下 mysql密码忘记
1.打开MySQL配置文件 my.ini中,添加上skip-grant-tables,可以添加到文件的末尾或者是这添加到[mysqld]的下面. 2.重启mysql 3.这时登录MySQL不再需要验证 ...
- cookie和session的使用和区别
cookie:存储在浏览器 存值:setcookie("名字",值,过期时间.秒,哪一个文件夹)//文件夹不写一般默认整个网站都可以 setcookie("usernam ...
- [Shell]Shell学习笔记之for
关于shell中的for循环用法很多,一直想总结一下,今天网上看到上一篇关于for循环用法的总结,感觉很全面,所以就转过来研究研究,嘿嘿…1. for((i=1;i<=10;i++));do e ...
- maven 发布 到 远程 tomcat
需要修改3个地方 首先 maven setting.xml 在 servers 节点 中 添加 一个 server <server> <id>devTomcat</id& ...
- Django 的 model form 组件
Django 的 model form 组件 Model Form 组件的由来 之前介绍过 Django 的 Form 组件(Django的Form表单)使用方法,Form 组件能够帮我们做三件事: ...
- P2913 [USACO08OCT]车轮旋转Wheel Rotation
传送门 初始状态是 0,如果有 1 的连接,0 就变 1,如果还有 1 的连接,1 就变 0,如果是 0 的连接就不变 所以就是把答案异或上所有连接,不用考虑顺序,反正最终是一样的 #include& ...
- Codeforces Round #316 (Div. 2) A
Description The country of Byalechinsk is running elections involving n candidates. The country cons ...