【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 ...
随机推荐
- InnoDB 引擎独立表空间
InnoDB 引擎独立表空间 使用过MySQL的同学,刚开始接触最多的莫过于MyISAM表引擎了,这种引擎的数据库会分别创建三个文件:表结构.表索引.表数据空间.我们可以将某个数据库目录直接迁移到 ...
- D. Easy Problem(简单DP)
题目链接:http://codeforces.com/contest/1096/problem/D 题目大意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在har ...
- VUE组件相关总结!
定义使用一个组件 <!doctype html> <html lang="en"> <head> <meta charset=" ...
- sicily 1459. The Dragon of Loowater
Time Limit: 1sec Memory Limit:32MB Description Once upon a time, in the Kingdom of Loowa ...
- mysql中间件 -> Atlas简介&安装
Atlas简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上, ...
- Redis相关链接
Redis 教程 http://www.runoob.com/redis/redis-data-types.html Python操作redis学习系列之(集合)set,redis set详解 (六) ...
- Python基础(2):__doc__、文档字符串docString、help()
OS:Windows 10家庭中文版,Python:3.6.4 Python中的 文档字符串(docString) 出现在 模块.函数.类 的第一行,用于对这些程序进行说明.它在执行的时候被忽略,但会 ...
- 【前端vue开发架构】vue开发单页项目架构总结
为营销活动设计的前端架构 主要的技术栈为 Vuejs,Webpack,请自行阅读如下技术或者框架的文档: 一.基础说明: node (https://nodejs.org/en/) npm (http ...
- 微信小程序入坑之自定义组件
前言 最近接触微信小程序,再次之前公司用的前端框架是vue ,然后对比发现,开发小程序是各种限制,对于开发者非常不友好.各种槽点太多,完全吐槽不过来,所以在此不多说,打算下次专门写一篇文章吐槽一下.本 ...
- No.6 selenium学习之路之下拉框Select
HTML中,标签显示为select,有option下拉属性的为Select弹框 1.Xpath定位 Xpath语法,顺序是从1开始,编程语言中是0开始