CF148D.Bag of mice
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
龙与公主正在争论除夕夜该做些什么。龙建议飞往山中,在月光下观赏精灵起舞;而公主则认为他们应该早点上床睡觉。为了达成友好的共识,他们决定将此事交由随机性决定。
他们轮流从一个袋子中抽取一只老鼠,袋中最初装有 w 只白鼠和 b 只黑鼠。第一个抽到白鼠的人获胜。每次龙抽完一只老鼠后,袋中剩余的老鼠会受惊,其中一只会自行跳出袋子(公主抽鼠时十分小心,不会吓到其他老鼠)。公主先抽。求公主获胜的概率。
如果袋中已无老鼠可抽,且此前无人抽到白鼠,则龙获胜。自行跳出袋子的老鼠不视为被抽取(不决定胜负)。一旦老鼠离开袋子,便永不返回。每次抽取时,袋中每只老鼠被抽到的概率均等;每次受惊跳出现象发生时,袋中每只剩余老鼠跳出的概率也均等。
输入格式
The only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).
输入数据仅包含一行,其中包含两个整数 w 和 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 exceed 10 - 9.
输出公主获胜的概率。若答案的绝对或相对误差不超过 10−9,则视为正确。
输入输出样例
输入#1
1 3
输出#1
0.500000000
输入#2
5 5
输出#2
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.
我们来分析第一个样例。公主在第一轮就抽到白鼠并立即获胜的概率为 1/4。龙在第一轮抽到黑鼠且未获胜的概率为 3/4 \* 2/3 = 1/2。此后袋中剩余两只老鼠——一只黑鼠和一只白鼠;其中一只随机跳出袋子,另一只由公主在第二轮抽取。若公主抽到的是白鼠,则她获胜(概率为 1/2 \* 1/2 = 1/4);否则无人获得白鼠,根据规则,龙获胜。
输入解题思路,AI测评打分。不知道怎么写?