简单题,做的比较水
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n,temp,t=0;
while(cin>>n&&n!=0)
{
vector<int>bricks(n);
t++;
int sum=0;
for(int i=0;i<n;i++)
{
cin>>bricks[i];
}
for(int i=0;i<n;i++)
{
sum+=bricks[i];
}
int avarage=sum/n;
int cont=0;
sort(bricks.begin(),bricks.end());
int r=n-1,l=0;
while(l<r)
{
while(bricks[l]<avarage&&bricks[r]>avarage)
{
bricks[l]++;bricks[r]--;cont++;
}
if(bricks[l]==avarage)
l++;
if(bricks[r]==avarage)
r--;
}
cout<<"Set #"<<t<<endl;
cout<<"The minimum number of moves is "<<cont<<"."<<endl<<endl;;
}
return 0;
}