D. Bag of mice
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).

Output

Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed10 - 9.

Examples
input
1 3
output
0.500000000
input
5 5
output
0.658730159
Note

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的更多相关文章

  1. CodeForces:148D-D.Bag of mice

    Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Program Description Th ...

  2. 【codeforces 148D】 Bag of mice

    http://codeforces.com/problemset/problem/148/D (题目链接) 题意 包中有w个白鼠,b个黑鼠.公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢.龙每画完一 ...

  3. 【Codeforces 105D】 Bag of mice

    [题目链接] http://codeforces.com/contest/148/problem/D [算法] 概率DP f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 : 1. ...

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

  5. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  6. Bag of mice(CodeForces 148D )

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. Bag of mice(概率DP)

    Bag of mice  CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...

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

  9. 【CF148D】 Bag of mice (概率DP)

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. (打补丁 )patch

    前言: diff:逐行比较文件的不同,并且显示出来. patch: 打补丁工具,将补丁打到老文件里面,也就是diff左边的那个文件,使得老文件和新文件一样 格式:diff [选项] 老文件 新文件 格 ...

  2. UEditor前端配置项说明

    UEditor 的配置项分为两类:前端配置项 和 后端配置项 后端配置项具体看这个文档L:后端配置项说明 本文档介绍如何通过设置前端配置项,定制编辑器的特性,配置方法主要通过修改ueditor.con ...

  3. app耗电量测试工具--PowerTutor

    PowerTutor是一款用来测试手机功耗的小工具,它可以只管地展示手机系统主要的组件和各种用户app产生的功耗数据.它可以统计app的屏幕功耗(LCD).CPU功耗以及WiFi和3G网络功耗,我们可 ...

  4. HDU4787_GRE Words Revenge

    这个题目做得泪牛满面. 题目为给你若干串,有的表示添加一个串,有的表示询问一个串有多少个字串为前面出现过的串. 题目一看就知道肯定是AC自动机(不过后缀自动机也是可以的) 但是细想就会发现AC自动机好 ...

  5. ZOJ3591_Nim

    题目的意思是给你n个ai,有多少种不同的连续段使得用该段数中所有的数字玩Nim游戏的先手必胜. 首先根据博弈论的知识,我们知道,要使先手必胜,那么只要保证所有的数的异或值不为0就可以了. 这个题目,给 ...

  6. python的N个小功能(连接数据库并下载相应位置的图片)

    #################################################################################################### ...

  7. 【bzoj4428】[Nwerc2015]Debugging调试 数论+记忆化搜索

    题目描述 一个 $n$ 行的代码出了bug,每行都可能会产生这个bug.你要通过输出调试,在其中加入printf来判断bug出现的位置.运行一次程序的时间为 $r$ ,加入一条printf的时间为 $ ...

  8. C++解析(3):布尔类型与三目运算符

    0.目录 1.布尔类型 2.三目运算符 3.小结 1.布尔类型 C++中的布尔类型: C++在C语言的基本类型系统之上增加了bool C++中的bool可取的值只有true和false 理论上bool ...

  9. 使用StoryBoard执行动画

    在WPF动画编程中,最常用的动画处理方式是DoubleAnimation动画,但是随着你的开发经验越来越多,你会发现,有时候使用这个动画类会很麻烦,因为这个动画是封闭动画,也就是说在动画的时间间隔内, ...

  10. WildFly8(JBoss)默认web服务器-------Undertow

    Java微服务框架之Undertow 一.Undertow简介: Undertow 是红帽公司(RedHat)的开源产品,是 WildFly8(JBoos) 默认的 Web 服务器. 官网API给出一 ...