首页 > ACM题库 > HDU-杭电 > HDU 2843-I Will Win-概率-[解题报告]HOJ
2014
02-17

HDU 2843-I Will Win-概率-[解题报告]HOJ

I Will Win

问题描述 :

Dumbear likes to play table tennis with his daughter � Quan. But Dumbear found that Quan played table tennis better and better recently, Dumbear wondered that Quan would defeat him someday. So he wants to know if he will win in the next match.

To simplify the problem, you can assume that the probability of Dumbear’s winning in each match is a constant number P (But Dumbear and you don’t know the number exactly). Of course 0 ≤ P ≤ 1. Dumbear had already taken N matches with Quan. And he won for M matches. He wants to know the expected probability of his winning for the next match. But Dumbear is very dumb, so he wants you to help him.

输入:

Each line of the input file contains two numbers N and M (0 ≤ M ≤ N) indicate the number of the matches Dumbear had taken and the number of matches Dumbear had won. The last line of the input file contains two numbers "0 0".

输出:

Each line of the input file contains two numbers N and M (0 ≤ M ≤ N) indicate the number of the matches Dumbear had taken and the number of matches Dumbear had won. The last line of the input file contains two numbers "0 0".

样例输入:

1 1
2 1
0 0

样例输出:

2 3
1 2

 


赢的概率恒为
P,现在知道已经进行的N场比赛中赢了M场,求P

 


一堆证明,其实我极其可能都证不出来,所以还不如猜想一下,结果必须都是很简单的。

http://blog.sina.com.cn/s/blog_6a46cc3f0100sffr.html

 

 

 

#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<cstring>

#include<algorithm>

using
namespace std;

int
gcd(int a, int b)

{

   
return b==0?a:gcd(b, a%b);

}

int
main()

{

   
int n, m;

   
while(~scanf(“%d%d”, &n,
&m)&&(n+m!=0))

   
{

       
n+=2;

       
m++;

 
      int
g=gcd(n, m);

       
printf(“%d %d\n”, m/g, n/g);

   
}

   
return 0;

}


解题参考:http://blog.sina.com.cn/s/blog_6a46cc3f0100t3tu.html


  1. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。