首页 > ACM题库 > HDU-杭电 > HDU 4015-Mario and Mushrooms[解题报告]HOJ
2015
04-15

HDU 4015-Mario and Mushrooms[解题报告]HOJ

Mario and Mushrooms

问题描述 :

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.

输入:

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)

输出:

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)

样例输入:

2
1 1
60 80

样例输出:

Case #1: 0.33333333
Case #2: 0.00020488

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include<queue>
#include <iostream>
#include <map>
using namespace std;


int main()
{
	int t,m,k;
	scanf("%d",&t);
	int cas=0;
	while(t--)
	{
		scanf("%d%d",&m,&k);
		printf("Case #%d: %.8f\n",++cas,1.0/(double)(m*k+1+k));
		
	}
	return 0;
}

  1. 约瑟夫也用说这么长……很成熟的一个问题了,分治的方法解起来o(n)就可以了,有兴趣可以看看具体数学的第一章,关于约瑟夫问题推导出了一系列的结论,很漂亮