Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位同仁给找一下错,(WA),是否是精度问题啊???

Posted by zhenly at 2006-09-30 12:02:32 on Problem 3015
#include<stdio.h>
int c(m,n);
void main()
{
	int n,m,i;
	int rank[50001];
	int aver,b;double u;
	scanf("%d%d",&n,&m);
	while(n!=0&&m!=0)
	{
		aver=0;
		for(i=1;i<=n;i++)
			scanf("%d",&rank[i]);
		u=(double)c(m,n);
		b=1;
		aver=(rank[m]-rank[n-m+1])*b;
		for(i=m+1;i<=n;i++)
		{
			b=b*(i-1)/(i-m);
			aver+=(rank[i]-rank[n-i+1])*b;
		}
		printf("%.3f\n",aver/u);
		scanf("%d%d",&n,&m);
	}
}
int c(m,n)
{
	int i,rel=1;
	if(m>n)
		return 0;
	else if(m==n)
		return 1;
	else
	{
		for(i=n;i>=n-m+1;i--)
		{
			rel*=i;
		}
		for(i=1;i<=m;i++)
			rel/=i;
		return rel;
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator