uva591 Box of Bricks
超级水题
View Code
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int T, f[56], i, k, s, j = 1; 6 while(scanf("%d",&T) && T) 7 { 8 s = k = 0; 9 for(i = 0;i < T; i++) 10 { 11 scanf("%d",&f[i]); 12 s += f[i]; 13 } 14 s /= T; 15 for(i = 0;i < T; i++) 16 k += abs(s-f[i]); 17 printf("Set #%d\n",j++); 18 printf("The minimum number of moves is %d.\n",k/2); 19 printf("\n"); 20 } 21 return 0; 22 }