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 ...
随机推荐
- SVMtrain的参数c和g的优化
SVMtrain的参数c和g的优化 在svm训练过程中,需要对惩罚参数c和核函数的参数g进行优化,选取最好的参数 知道测试集标签的情况下 是让两个参数c和g在某一范围内取离散值,然后,取测试集分类准确 ...
- 005zabbix3.0报错记录
一.问题描述 在zabbix_server添加变量时,出现了以下的报错,
- git中如何查看一个文件的修改(更新)历史
有些时候有些文件或文件夹被移除了, 或者更换了路径或被改名了, 想跟踪一下这个文件被修改(更新)的历史, 可以用如下命令: git log -p matser -- filename 格式是: git ...
- 常见的 JavaScript 内存泄露
什么是内存泄露 指由于疏忽或错误造成程序未能释放已经不再使用的内存.内存泄漏并非指内存在物理上的消失, 而是应用程序分配某段内存后,由于设计错误,导致在释放该段内存之前就失去了对该段内存的控制,从而造 ...
- 关于U3D中的移动和旋转
关于移动,其实很简单,就是移动: 第一个参数标识移动的距离,是一个矢量:第二个参数是因为游戏对象有自己的坐标系,还有一个世界坐标系,使用的坐标系不同将导致运动的结果不同: function Trans ...
- 线性SVM的推导
线性SVM算法的一般过程 线性SVM的推导 超平面方程 SVM是用来分类的.给定一系列输入数据(n维向量),需要找到一个切分界线(n-1维的超平面),这里假定数据是线性可分的.比如,二维数据的超平面是 ...
- 用递归法计算从n个人中选选k个人组成一个委员会的不同组合数
用递归法计算从n个人中选选k个人组成一个委员会的不同组合数. 分析 由n个人里选k个人的组合数= 由n-1个人里选k个人的组合数+由n-1个人里选k-1个人的组合数: 当n = k或k = 0时,组合 ...
- 【PAT】1009. 说反话 (20)
1009. 说反话 (20) 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其 ...
- [实战]MVC5+EF6+MySql企业网盘实战(11)——新建文件夹2
写在前面 上篇文章实现了创建文件夹的功能,这里面将实现单击文件夹,加载列表的功能. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网 ...
- Rookey.Frame v1.0快速开发平台-用户登录
上一次介绍的了Rookey.Frame v1.0快速开发平台的整体功能,接下来会对各个功能点进行解析说明,今天给大家介绍下系统登录功能. 用户登录 系统中基本上所有功能页面都是从后台代码拼接后返回的, ...