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/problem/D
Description
Input
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.
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 Input
2 2 2
Sample Output
0.333333333333 0.333333333333 0.333333333333
HINT
题意
有个地方有三种人,分别是石头,剪刀,步
每天都会有俩不同种族的人出来,然互石头会杀死剪刀,剪刀会杀死步,步会干掉石头
然后问你,在最后,每个种族活到最后的概率是多少
题解:
概率dp,dp[i][j][k]表示,剩下人数为i,j,k的概率,转移方程:
double tmp=(i+j+k)*(i+j+k-)/-(i*(i-)/)-j*(j-)/-k*(k-)/;
//总共有多少种选择方法
if (j>&&i>)
dp[i][j-][k]+=dp[i][j][k]*i*j/tmp;
//选择石头剪刀的概率
if (j>&&k>)
dp[i][j][k-]+=dp[i][j][k]*j*k/tmp;
//选择剪刀布的概率
if (i>&&k>)
dp[i-][j][k]+=dp[i][j][k]*k*i/tmp;
//选择布和石头的概率
水DP = =
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** double dp[][][]; int main()
{
int r,s,p;
cin>>r>>s>>p;
dp[r][s][p]=;
double ans1=,ans2=,ans3=;
for(int i=r;i>=;i--)
{
for(int j=s;j>=;j--)
{
for(int k=p;k>=;k--)
{
double tmp=(i+j+k)*(i+j+k-)/-(i*(i-)/)-j*(j-)/-k*(k-)/;
if (j>&&i>)
dp[i][j-][k]+=dp[i][j][k]*i*j/tmp;
if (j>&&k>)
dp[i][j][k-]+=dp[i][j][k]*j*k/tmp;
if (i>&&k>)
dp[i-][j][k]+=dp[i][j][k]*k*i/tmp;
}
}
}
for(int i=r;i>=;i--)
ans1+=dp[i][][];
for(int j=s;j>=;j--)
ans2+=dp[][j][];
for(int k=p;k>=;k--)
ans3+=dp[][][k];
printf("%.10f %.10f %.10f\n",ans1,ans2,ans3);
}
Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP的更多相关文章
- Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]
D. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
D. Painting The Wall ...
- Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp
E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock
题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...
- CodeForces Round #301 Div.2
今天唯一的成果就是把上次几个人一起开房打的那场cf补一下. A. Combination Lock 此等水题看一眼样例加上那个配图我就明白题意了,可是手抽没有注释掉freopen,WA了一发. #in ...
随机推荐
- imperva配置文件的导入导出
imperva配置文件的导入导出 Full_expimp.sh //进行备份 1导入 2导出 输入密码后 1 全部导出 是否想导出失败的数据 默认密码是system的密码 输入导出的路径 ...
- malloc原理和内存碎片【转】
转自:http://www.cnblogs.com/zhaoyl/p/3820852.html 当一个进程发生缺页中断的时候,进程会陷入内核态,执行以下操作: 1.检查要访问的虚拟地址是否合法 2.查 ...
- STL hashtable阅读记录
unordered_map,unordered_set等相关内容总结: unordered_map和unordered_set是在开发过程中常见的stl数据结构.其本质是hashtable.在SGI_ ...
- 离线部署ELK+kafka日志管理系统【转】
转自 离线部署ELK+kafka日志管理系统 - xiaoxiaozhou - 51CTO技术博客http://xiaoxiaozhou.blog.51cto.com/4681537/1854684 ...
- Mysql 中 char 、varchar 、text的区别
首先它们的存储方式和数据的检索方式都不一样.数据的检索效率是:char > varchar > text 空间占用方面,就要具体情况具体分析了. char:存储定长数据很方便,CHAR字段 ...
- gdb安装
1.卸载原有gdb 以root用户登录 1.1 查询原有gdb包名,执行命令: rpm -q gdb 1.2 卸载原有gdb包,假设gdb包名为gdb-7.0-0.4.16,执行命令:rpm - ...
- python实现链式调用
在python中实现链式调用只需在函数返回对象自己就行了. class Person: def name(self, name): self.name = name return self def a ...
- acm专题---dfs+bfs
题目来源:http://hihocoder.com/problemset/problem/1049 #1049 : 后序遍历 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描 ...
- Webmin忘记密码解决方法,及配置文件介绍
Webmin忘记Web登陆时候的密码,无法登陆了,Google了一下,基本方法是通过changepass.pl可以修改密码 首先找到changepass.pl这个文件目录 $sudo locate c ...
- n*m的矩阵,行和列都递增有序,求是否出现target元素(面试题)
题目描述:给定一个n*m的矩阵,矩阵的每一行都是递增的,每一列也是递增的,给定一个元素target,问该target是否在矩阵中出现. 思路:先从最左下角的元素开始找,三种情况: 1. 如果该元素大于 ...