Codeforces 148 D Bag of mice
2 seconds
256 megabytes
standard input
standard output
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.
They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?
If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.
The only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).
Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed10 - 9.
1 3
0.500000000
5 5
0.658730159
Let's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag — one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins.
大佬题解:http://blog.csdn.net/swust_Three/article/details/68941926
#include<cstdio>
using namespace std;
double dp[][];
int main()
{
int w,b;
scanf("%d%d",&w,&b);
for(int i=;i<=w;i++) dp[i][]=1.0;
for(int i=;i<=w;i++)
for(int j=;j<=b;j++)
{
dp[i][j]=1.0*i/(i+j);
if(j>=) dp[i][j]+=1.0*j/(i+j)*(j-)/(i+j-)*(j-)/(i+j-)*dp[i][j-];
if(j>=) dp[i][j]+=1.0*j/(i+j)*(j-)/(i+j-)*i/(i+j-)*dp[i-][j-];
}
printf("%.9lf",dp[w][b]);
}
Codeforces 148 D Bag of mice的更多相关文章
- CodeForces:148D-D.Bag of mice
Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Program Description Th ...
- 【codeforces 148D】 Bag of mice
http://codeforces.com/problemset/problem/148/D (题目链接) 题意 包中有w个白鼠,b个黑鼠.公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢.龙每画完一 ...
- 【Codeforces 105D】 Bag of mice
[题目链接] http://codeforces.com/contest/148/problem/D [算法] 概率DP f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 : 1. ...
- 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 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- Bag of mice(CodeForces 148D )
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- CF 148D. Bag of mice (可能性DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 【CF148D】 Bag of mice (概率DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- java 数据库查询Date类型字段 没有了时分秒 全为 00 的解决办法
当取出这个值的时候只能用java.sql.Date而且只能显示年月日,我想知道如何才能显示时分秒 PS:不改变用getdate()存入的前提下! 解决方法:将getDate()方法改为getTim ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- 第七周C语言代码
#ifndef NMN_LIST_H #define NMN_LIST_H #include <stdio.h> struct list_head { struct lis ...
- HTML图片标签
<body> <!-- 使用img标签来向网页中引入外部的图片, img标签也是一个自结束标签 属性: src:设置一个外部图片的路径 alt:可以用来设置图片不能显示时,就会显示图 ...
- python基础(一)简单入门
一.第一个python程序 1.交互式编程 直接在命令行里面输入python即可进入python交互式命令行,linux下一样: 在 python 提示符中输入以下文本信息,然后按 Enter 键查看 ...
- RGB555转RGB565
做tft彩屏显示图片的时候,显示16位位图,显示屏的显示模式为RGB565.使用img2lcd转换后的16位bmp,显示出来后,颜色有偏差:转换为565格式的bin文件,显示完全正常,可以确定转换为b ...
- 超链接提示效果jQuery+CSS+html
我们知道浏览器自带了超链接提示, 只需要在超链接中加入 title 属性就可以了. <a href="#" title="吉大砍人案致1死1伤 受害者死前大喊他手里 ...
- 洛谷 P2574 XOR的艺术
刚刚学了,线段树,一道线段树入门题试试水 下面是题面 题目描述 AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个 ...
- Windows与VMware中的CentOS系统互通访问
[步骤01]设置 CentOS 虚拟机-网络适配器为“桥接模式(直接连接物理网络),复制物理网络连接状态” [步骤02]配置虚拟网卡 [步骤03]配置 CentOS 网络 [步骤04]测试 windo ...
- QoS专题-第3期-QoS实现之报文简单分类与标记
QoS实现之报文简单分类与标记 上一期专题我们讲到,MQC中的流分类可以实现报文的分类,流行为可以对报文进行重标记,从而实现对流量的精细化差分服务.而优先级映射则可以根据802.1p优先级.DSCP优 ...