17.5.18E - Mario and Mushrooms HDU - 4015 概率题

Description
Mario usually relaxes himself by walking along the shady track near the Mushroom Kingdom. The evil King Koopa noticed that and placed a lot of mushroom on the road. There are two types of mushrooms, max mushrooms and bad mushrooms. The bad mushrooms will decrease Mario’s HP by m points, on the other hand, max mushrooms will increase Mario’s HP by one point. The mushrooms are randomly placed on the track and Mario will receive them one by one. Once Mario’s HP becomes zero or below after he received a mushroom, he will die.
Notice that Mario begins with HP zero, so if the first mushroom is bad, Mario will die immediately. Fortunately, if Mario receives all the mushrooms, he will be alive with HP 1. In the other words, if there are k bad mushrooms on the way, there will also be m*k+1 max mushrooms.
Princess Peach wants to know the possibility for Mario staying alive. Please help her to calculate it out.

Input
There are several test cases. The first line contains only one integer T, denoting the number of test cases.
For each test case, there is only one line including two integers: m and k, denoting the amount of points of HP the Mario will decrease if he receives a bad mushroom, and the number of bad mushrooms on the track. (1 <= m <= 1000, 1 <= k <= 1000)

Output
For each test case, output only real number denoting the possibility that Mario will survive if he receives all the randomly placed mushrooms one by one. The answer should be rounded to eight digits after the decimal point.

Sample Input
2
1 1
60 80

Sample Output

Case #1: 0.33333333
Case #2: 0.00020488

大意:
马里奥从 A 至 B 地采蘑菇,初始 HP = 0 ;碰到好蘑菇一次 +1 HP 碰到烂蘑菇一次 -m HP ; 最后 HP =1 视为存活
求存活概率
多组输入 给出蘑菇攻击力 m 和 毒蘑菇数量 k

考虑这样的一次排列:
每组都为 m 个好蘑菇后跟 1 个烂蘑菇 有 k 个烂蘑菇则总数为 k*m+k+1 个蘑菇
易得 k*m+k+1 个蘑菇的其他排列方式都不符合 (即不能移动烂蘑菇的位置了) 则概率为

1km+k+1

每个排列都是这个原理 因此 概率为
1km+k+1

PS.据说是鸽巢原理,已经忘光了。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值