CF 148D D. Bag of mice (概率DP||数学期望)
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 exceed 10 - 9.
Example
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.
题意:
一对情侣开房玩抓老鼠游戏,老鼠有黑白两色,女的为先手,先抓到白老鼠胜。特别的,男的每抓一只老鼠后,也会随机放走一只老鼠。问女的赢的概率是多少。如果输了,后果会很严重,当天晚上只能睡沙发。
思路:
dp[i][j]为当前状态,有i只白老鼠,j只黑老鼠,女的赢的概率。那么dp[][] = 这一次赢 + 以后赢= i/(i+j) + 。。。具体如下。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
double dp[][]; int w,b,i,j;
int main()
{
while(~scanf("%d%d",&w,&b)){
memset(dp,,sizeof(dp));
for(i=;i<=w;i++)
for(j=;j<=b;j++){
if(i==) { dp[i][j]=; continue;}
if(j==) { dp[i][j]=1.0; continue;}
dp[i][j]=1.0*i/(i+j);
if(j>=) dp[i][j]+=(1.0*j/(i+j))*(j-)/(i+j-)*i/(i+j-)*dp[i-][j-];
if(j>=) dp[i][j]+=(1.0*j/(i+j))*(j-)/(i+j-)*(j-)/(i+j-)*dp[i][j-]; }
printf("%.9lf\n",dp[w][b]);
}return ;
}
CF 148D D. Bag of mice (概率DP||数学期望)的更多相关文章
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- CF 148D Bag of mice 概率dp 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CF 148D D Bag of mice (概率dp)
题目链接 D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforce 148D. Bag of mice[概率dp]
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- 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(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- 抓老鼠 codeForce 148D - Bag of mice 概率DP
设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率. 那么当i = 0 时,为0 当j = 0时,为1 公主可直接取出白老鼠一只赢的概率为i/(i+j) 公主取出了黑老鼠,龙必然 ...
随机推荐
- Linux基础知识点
1.目录结构 bin 存放二进制可执行文件(ls,cat,mkdir等) boot 存放用于系统引导时使用的各种文件 dev 用于存放设备文件 etc 存放系统配置文件 home 存放所有用户文件的根 ...
- Elasticsearch Head 集群健康值:未连接
安装elasticsearch 6.0 x-pack后,登录9200端口需要用户和密码, 这样,在使用elasticsearch head时,就不能直接访问9100了. 按照官方文档的要求,http ...
- kubernetes源码分析 -- kube-proxy
Kube-proxy需要在每一个minion结点上运行.他的作用是service的代理,负责将业务连接到service后面具体执行结点(endpoints). 我们列一下体现kube-proxy ...
- 利用javascript实现页面截图
html2canvas可以通过纯JS对浏览器端经行截屏,但截图的精确度还有待提高,部分css不可识别,所以在canvas中不能完美呈现原画面样式 兼容性: Firefox 3.5+ Google Ch ...
- http协议报头详解
目录: 1. http协议简介 2. http报头举例 3. http报头详解 4. 几个字段的说明 5. 总结 6. 参考文章 1. http协议简介 HTTP是Hyper Text Transfe ...
- js今日小结—Ajax、前端安全、GET&POST、闭包、HTTPS
HTTPS HTTP+加密(SSL.TLS)+认证+完整性保护 = HTTPS: GET和POST的区别 get拉取数据,post传输数据 get请求能被浏览器主动缓存,post不会(除非手动) ge ...
- jmeter-01 JMeter HTTP测试的各元件功能演示示例
最小的测试将包括测试计划,线程组和一个或多个采样器. Jmeter HTTP测试的各元件演示示例 功能逻辑:wap官网(a.4399sy.com.hk),每个用户登录一次,发帖2次,发帖成功后注销退出 ...
- 重新学习MySQL数据库2:『浅入浅出』MySQL 和 InnoDB
重新学习Mysql数据库2:『浅入浅出』MySQL 和 InnoDB 作为一名开发人员,在日常的工作中会难以避免地接触到数据库,无论是基于文件的 sqlite 还是工程上使用非常广泛的 MySQL.P ...
- 1-25-循环控制符break、continue和函数详解
大纲: 1-for循环补充 1-1-for循环实战---类C格式应用 2-break.continue循环控制符 2-1实战:帮助理解break.continue作用 3-函数详解 3-1.脚本文件中 ...
- 简明 Nginx Location Url 配置笔记
基本配置 为了探究nginx的url配置规则,当然需要安装nginx.我使用了vagrant创建了一个虚拟环境的ubuntu,通过apt-get安装nginx.这样就不会污染mac的软件环境.通过vr ...