`
java-mans
  • 浏览: 11428171 次
文章分类
社区版块
存档分类
最新评论

hdu3959-求期望

 
阅读更多

期望:对于一个数值x,x出现的概率是p,那么x的期望值就是x*p;

题意:

比较不好理解,expected number of times we will need to throw dice to determine the judge.选出裁判需要掷骰子的次数的期望。

m^x>=n;即每个人提供长为x的序列,序列总长m^x。掷骰子x次选出裁判的概率p=m^x/n;那么x的期望值为:x*p;即:m^x*x/n

题中n<10^9.gcd时数据应为long long。【杭电long longWA,改为__int64后AC】

代码:

#include<stdio.h>
__int64 gcd(__int64 a,__int64 b)
{
	__int64 c;
	while(b!=0)
	{
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}
int main()
{
	int t;__int64 n,m;
	scanf("%d",&t);
	int cnt=0;
	while(t--)
	{
		cnt++;
		scanf("%I64d%I64d",&n,&m);
		__int64  x=1,k=0;
		while(x<n)
		{
			x*=m;k++;
		}
		x=x*k;
		m=gcd(x,n);
		x/=m;n/=m;
		printf("Case %d: %I64d/%I64d\n",cnt,x,n);
	}
	return 0;
}        

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics