HDU 4015 Mario and Mushrooms (raney引理)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Roll_Keyboard/article/details/79966500

题意:

思路:

虽然结论很好猜,但正确想法是raney引理
Raney引理:
设整数序列A={Ai,i=1,2,…,N},且部分和为Sk=A1+,…,+Ak,序列中的所有的数字之和为Sn=1;则在A的N个循环表示中,有且仅有一个序列B,满足B的任意部分和Si均大于零。

错误及反思:

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    for(int i=1;i<=T;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        printf("Case #%d: %.8f\n",i,1.0/(a*b+1+b));
    }
}

Mario and Mushrooms

12-10

Problem DescriptionnMario 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.nNotice 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.nPrincess Peach wants to know the possibility for Mario staying alive. Please help her to calculate it out.n nnInputnThere are several test cases. The first line contains only one integer T, denoting the number of test cases.nFor 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)n nnOutputnFor 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.n nnSample Inputn2n1 1n60 80n nnSample OutputnCase #1: 0.33333333nCase #2: 0.00020488n

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭