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. FivePlus——分工理解

    最终的游戏方案 游戏采用回合制,每回合双方英雄各自轮流选择移动和攻击以及大招,选择结束进行结算 英雄/小兵/塔的攻击力/大招效果参照作业要求,如果发现不均衡再进行调整 UI界面考虑使用QT或者命令行界 ...

  2. 0324操作系统cmd功能的扩展

    需求:1.实现清屏功能 2.实现不区分大小写功能 3.添加功能能添加新的命令符 设计:1.使用system("cls")清屏. 2.使用strlwr()函数把大写都变成小写 3.( ...

  3. 使用 python 管理 mysql 开发工具箱 - 2

    这篇博文接着上篇文章<使用 python 管理 mysql 开发工具箱 - 1>,继续写下自己学习 python 管理 MySQL 中的知识记录. 一.MySQL 的读写分离 学习完 My ...

  4. WPF/MVVM快速指引

    简介 最近微软推出了UWA,又是一波新的C#+xaml学习热.好多小伙伴都对MVVM感觉很好奇,但是有些地方也有点难以理解.特意写了这边文章,希望对你有帮助. 这边文章会很长,所以我会用几个例子的形式 ...

  5. Java String简单知识点总结

    1.字符串的比较 public void run(){ //str1在池中 String str1 = new String("String"); //str2,str3 存在于堆 ...

  6. pyspark在windows中的安装

    0.安装python,我用的是python2.7.13 1.安装jdk 一定要安装1.7以上的版本,安装低版本会报下面的错误 java.lang.NoclassDefFoundError 安装后不用手 ...

  7. ONS发布订阅消息

    ONS, 全名Open Notification Service, 是阿里基于开源消息中间件RocketMQ的一个云产品. 首先,要申请阿里账号等.本地也可以申请阿里云账号自己调试.此处为公司拥有阿里 ...

  8. java 重写父类构造器

  9. 如何在Word中排出漂亮的代码

    引言 学数学和计算机,当然还是用LaTeX排版技术文章更方便.但有时候还是迫不得已需要用Word写作,另外Word其实也有Word的好处,比如细节上的修改要比LaTeX方便. 从Matlab高亮代码复 ...

  10. 【Mybatis】<foreach>标签在mybatis中的使用

    mapper.xml如下: <select id="selectCkspcb" parameterType="java.util.Map" resultT ...