HDU2843 概率论水题

啦啦啦啦啦     我是传送门,快点我看题目


I Will Win

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 398    Accepted Submission(s): 246


Problem Description
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.
 

Input
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".
 

Output
For each line, output two integers A and B indicates the expected probability of Dumbear’s winning for the next match is A / B. Make sure that gcd(A, B) = 1!
 

Sample Input
      
      
1 1 2 1 0 0
 

Sample Output
      
      
2 3 1 2

题目大意:有个小孩和爸爸一起打乒乓球,小孩越打越好,爸爸就有点担心了,想知道自己下一局赢的期望概率*.*,给你他们比赛的局数n,爸爸赢的局数m,要你求P,P的分子为A,分母为B

你们看  公式就是这么简单[转载][HDU <wbr>2843][TJU <wbr>3319] <wbr>I <wbr>Will <wbr>Win,具体推导详见百度,我们怎么样求最简分数呢,当然是用gcd咯,具体代码如下:

#include <iostream>
using namespace std;
int gcd(int x,int y)
{
	if (y==0) return x;
	if(x<y)
		return gcd(y,x);
	else
		return gcd(y,x%y);
}
int main()
{
	int n,m,a,b;
	while(cin>>n>>m)
	{
		if(n==0&&m==0)
			break;
		a=m+1;
		b=n+2;
		int t=gcd(a,b);
		a=a/t;
		b=b/t;
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值