题意: 求变成一样的最少移动个数。。。直接求平均后,将大于平均值的个数相加就行了
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int arr[100];
int sum,n;
int main()
{
int cas = 1;
while (scanf("%d",&n) != EOF && n )
{
sum = 0 ;
for (int i = 0 ; i < n ; i++)
{
scanf("%d",&arr[i]);
sum += arr[i];
}
int ans = sum / n ;
int step = 0 ;
for (int i = 0 ; i < n ; i++)
if (arr[i] > ans)
step += arr[i] - ans;
printf("Set #%d\n",cas++);
printf("The minimum number of moves is %d.\n",step);
printf("\n");
}
return 0;
}