Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
直接贴代码供大家参考#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator