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 ...
随机推荐
- Metlnfo CMS全版本漏洞收集
根据https://www.seebug.org/appdir/MetInfo 进行书写. [版本:Metlnfo 4.0] 漏洞标题:Metlnfo cms任意用户密码修改 漏洞文件:member/ ...
- ThinkPHP的运行流程-1
我在index\Lib\Action\目录下新建了一个ShowAction.class.php文件.ps:该目录是控制器的目录. 然后这个文件中继承了action这个类.代码如下: 1 2 3 4 5 ...
- sed的额外用法(网摘)
#在我开始动手写一个一个的脚本的时候才会看到更多的用法 1. 在某行的前一行或后一行添加内容(前提是要确定行的内容) # 匹配行前加 sed -i '/allow/ideny' httpd.conf ...
- HTTPS握手过程
HTTPS在HTTP的基础上加入了SSL协议,SSL依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密.具体是如何进行加密,解密,验证的,且看下图,下面的称为一次握手. 1. 客户端发起HT ...
- LightOJ - 1297 Largest Box LightOJ(一元三次方程求极大值)
题目链接:https://vjudge.net/contest/28079#problem/K 题目大意:给你一个长为L,宽为W的纸片,四个角剪掉边长为x的正方形,如下图所示,然后折成一个无盖的纸盒, ...
- hive学习(四) hive的函数
1.内置运算符 1.1关系运算符 运算符 类型 说明 A = B 所有原始类型 如果A与B相等,返回TRUE,否则返回FALSE A == B 无 失败,因为无效的语法. SQL使用”=”,不使用”= ...
- C++的黑科技(深入探索C++对象模型)
周二面了腾讯,之前只投了TST内推,貌似就是TST面试了 其中有一个问题,“如何产生一个不能被继承的类”,这道题我反反复复只想到,将父类的构造函数私有,让子类不能调用,最后归结出一个单例模式,但面试官 ...
- Linux下的格式化字符串漏洞利用姿势
linux最早的漏洞防护机制nx-stack刚刚出现后就有人想出了突破方法.那就是只有栈是不可执行,而除了栈以外的其他地方还是可以执行的,只要把返回地址执行别的地方就可以. 一.格式化字符串漏洞 格式 ...
- Java学习(匿名对象、内部类、包、import、代码块)
一.匿名对象 概念:匿名对象是指在创建对象时,只有创建的语句,却没有把对象地址值赋给某个变量. 特点: (1)匿名对象直接使用,没有变量名.当做形参使用. new Person().name=&quo ...
- 为啥我喜欢在Windows 7环境下做Unity开发?
先说明,以下情况只针对本人哦~ 前阵子我在OSX的最新版本Mavericks下做Unity开发,后来我把MacbookPro卖了,自己组装了个PC搞开发,为啥呢? 1:OSX下 MonoDevelop ...