题目描述:

Bad Luck Island

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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.

Examples

Input

Copy

2 2 2

Output

Copy

0.333333333333 0.333333333333 0.333333333333

Input

Copy

2 1 2

Output

Copy

0.150000000000 0.300000000000 0.550000000000

Input

Copy

1 1 3

Output

Copy

0.057142857143 0.657142857143 0.285714285714

思路:

这道题刚看的时候觉得好神奇啊,一定要用到好高大上的概率知识,但是我的数学已经丢完了,只能跳过了。知道了解法之后更觉得神奇,啊~神奇的概率dp。

定义dp[i][j][k]是物种石头剩下i个,剪刀剩下j个,布剩下k个的情形发生的概率。刚开始时dp[r][s][p]=1,现在考虑状态转移。

什么时候剪刀会少一个呢?它遇到了石头,这种情况发生的概率呢?\(\frac{C_s^1*C_r^1}{C_{r+s+p}^2}\),同理少一个布呢?它遇到了剪刀,概率呢?\(\frac{C_p^1*C_s^1}{C_{r+s+p}^2}\),石头少一个的概率是\(\frac{C_p^1*C_r^1}{C_{r+s+p}^2}\),那么状态转移方程是

\[sum=sr+pr+sp
\]

\[dp[i-1][j][k]+=dp[i][j][k]*\frac{C_s^1*C_r^1}{sum}
\]

\[dp[i][j-1][k]+=dp[i][j][k]*\frac{C_p^1*C_r^1}{C_{sum}^2}
\]

\[dp[i][j][k-1]+=dp[i][j][k]*\frac{C_p^1*C_s^1}{C_{sum}^2}
\]

从头开始递推即可。

最后统计答案的时候统计dp[i][j][0]这种的答案,因为这种答案的胜负已定,只能存在一个物种

代码:

#include <iostream>
#include <iomanip>
#define max_n 105
using namespace std;
int r,s,p;
double dp[max_n][max_n][max_n];
int main()
{
cin >> r >> s >> p;
dp[r][s][p] = 1.0;
for(int i = r;i>0;i--)
{
for(int j = s;j>0;j--)
{
for(int k = p;k>0;k--)
{
double sum = i*j+i*k+j*k;
dp[i-1][j][k] += dp[i][j][k]*(double)(i*k)/sum;
dp[i][j-1][k] += dp[i][j][k]*(double)(i*j)/sum;
dp[i][j][k-1] += dp[i][j][k]*(double)(j*k)/sum;
}
}
}
double ans1 = 0;
double ans2 = 0;
double ans3 = 0;
for(int i = 0;i<=100;i++)
{
for(int j = 0;j<=100;j++)
{
ans1 += dp[i][j][0];
ans2 += dp[0][i][j];
ans3 += dp[i][0][j];
}
}
cout.setf(ios_base::fixed,ios_base::floatfield);
cout << setprecision(12) << ans1 << " " << ans2 << " " << ans3 << endl;
return 0;
}

Codeforces B. Bad Luck Island(概率dp)的更多相关文章

  1. codeforces 540D Bad Luck Island (概率DP)

    题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...

  2. 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 ...

  3. Codeforces 540D Bad Luck Island - 概率+记忆化搜索

    [题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...

  4. cf540D. Bad Luck Island(概率dp)

    题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存 ...

  5. CodeForces - 540D Bad Luck Island —— 求概率

    题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...

  6. CodeForces 540D Bad Luck Island (DP)

    题意:一个岛上有石头,剪刀和布,规则就不用说了,问你最后只剩下每一种的概率是多少. 析:很明显的一个概率DP,用d[i][j][k]表示,石头剩下 i 个,剪刀剩下 j 个,布剩下 k 个,d[r][ ...

  7. codeforces 148D Bag of mice(概率dp)

    题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...

  8. CodeForces 24D Broken robot (概率DP)

    D. Broken robot time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces 148D Bag of mice 概率dp(水

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...

随机推荐

  1. 团队作业第五次—项目冲刺-Day1

    Day1 项目相关 作业相关 具体描述 所属班级 2019秋福大软件工程实践Z班 作业要求 团队作业第五次-项目冲刺 作业正文 hunter--冲刺集合 团队名称 hunter小组 作业目标 最终做出 ...

  2. 配置Nginx的防盗链

    实验环境 一台最小化安装的CentOS 7.3虚拟机 配置:1核心/512MB nginx版本1.12.2 一.配置盗链网站 1.启动一台nginx虚拟机,配置两个网站 vim /etc/nginx/ ...

  3. c++隐式转换(implicit conversion)

    1.缘由 最近在使用nlohmann的json,发现有些地方不是特别好用,所以就想自己修改一下(目的是为了增加类似jsoncpp中可以//增加注释的功能),在看源码的时候看到了一个迷惑的地方,就是解析 ...

  4. FPGA硬件加速

    FPGA市场占有率最高的两大公司Xilinx和Altera. 查找表(Look-Up-Table)简称为LUT,LUT本质上就是一个RAM.目前FPGA中多使用4输入的LUT,所以每一个LUT可以看成 ...

  5. Tarjan 算法求 LCA / Tarjan 算法求强连通分量

    [时光蒸汽喵带你做专题]最近公共祖先 LCA (Lowest Common Ancestors)_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili tarjan LCA - YouTube Tarj ...

  6. [技术博客]海报图片生成——小程序canvas画布

    目录 背景介绍 canvas简介 代码实现 难点讲解 圆角矩形裁剪失败之PS的妙用 编码不要过硬 对过长的文字进行截取 真机首次生成时字体不对 drawImage只能使用本地图片 背景介绍 目标:利用 ...

  7. mysql 基本操作 一

    1.mysql 管理语句 1)展示数据库列表 mysql> show databases; +--------------------+ | Database | +-------------- ...

  8. 由浅入深了解NB-IoT | 我的物联网成长记

    [摘要] 什么是NB-IoT?NB-IoT有什么优势?NB-IoT能做什么?本文将会从NB-IoT技术的发展历程,技术特点,通信协议,应用场景等方面为您全方面解读NB-IoT技术,了解NB-IoT的独 ...

  9. LeetCode dp专题

    1. 动态规划的适用场景 动态规划常常适用于有重叠子问题和最优子结构性质的问题,动态规划方法所耗时间往往远少于朴素解法. 2. 动态规划的基本思想 动态规划背后的基本思想非常简单.大致上,若要解一个给 ...

  10. SQL Server 中获取一个表的字段信息

    直接贴代码了: SELECT sysobjects.name AS TableName, syscolumns.Id AS TableId, syscolumns.name AS DbColumnNa ...