1. 程式人生 > >HDU-4015:Mario and Mushrooms(找規律)

HDU-4015:Mario and Mushrooms(找規律)

Mario and Mushrooms

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 872    Accepted Submission(s): 661  

Problem 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

 

Source

 

Recommend

lcy

我把簡化的題意跟隊友說了下,隊友瞬間開了這題哈哈哈哈!! 我看完題目不會排列!!還以為會很難

【題意】

輸入m,k,m是遇到一個壞蘑菇時生命值減少的點數,k是共有幾個壞蘑菇,(根據題目給的公式)好蘑菇有m*k + 1個

所以,蘑菇總數 = m * k + 1 + k

其實拿第一個樣例推下就能找到規律~~但是我比賽的時候沒想到(撓頭

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define og(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))

int main()
{
    int t,m,k; 
    scanf("%d",&t);
    go(i,1,t)
    {
        scanf("%d%d",&m,&k);
        printf("Case #%d: %.8lf\n",i,1.0/(m*k+1+k));
    }
    return 0;
}