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

直接贴代码供大家参考

Posted by 244549721 at 2011-07-26 15:09:53 on Problem 1477
#include<stdio.h>
#include<math.h>
main()
{
	int n,i,a[50],sum,tern,k=0;
	while(scanf("%d",&n)!=EOF&&n!=0)
	{
		k++;
		sum=tern=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++)
		{
			sum+=a[i];
		}
		sum=sum/n;
			for(i=0;i<n;i++)
		{
			tern+=fabs(sum-a[i]);
		}
			printf("Set #%d\nThe minimum number of moves is %d.\n",k,tern/2);printf("\n");
		

	}
	
}

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