這道題其實沒想通。。。為什么說是最小數呢
我覺得就是大于平均數的去減平均數,然后相加就是了,還有其他更復雜的情況嗎?
簡單題終于AC了。。。
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;


int main()


{
int n;
vector<int> number;
vector<int> setcount;
while (1)

{
cin>>n;
if (n==0)

{
break;
}
int bricks;
number.clear();
while (n>0)

{
cin>>bricks;
number.push_back(bricks);
n--;
}
int sum=0;
for (size_t i=0;i<number.size();i++)

{
sum+=number[i];
}
int aver=sum/(int)number.size();
if (sum%(int)number.size()!=0)

{
break;
}
int count=0;
for (size_t j=0;j<number.size();j++)

{
if (number[j]>aver)

{
count+=number[j]-aver;
}
}
setcount.push_back(count);
}
for (int i=0;i<(int)setcount.size();i++)

{
cout<<"Set #"<<i+1<<endl;
cout<<"The minimum number of moves is "<<setcount[i]<<".\n"<<endl;
}
}
我覺得就是大于平均數的去減平均數,然后相加就是了,還有其他更復雜的情況嗎?
簡單題終于AC了。。。
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main()

{
int n;
vector<int> number;
vector<int> setcount;
while (1)
{
cin>>n;
if (n==0)
{
break;
}
int bricks;
number.clear();
while (n>0)
{
cin>>bricks;
number.push_back(bricks);
n--;
}
int sum=0;
for (size_t i=0;i<number.size();i++)
{
sum+=number[i];
}
int aver=sum/(int)number.size();
if (sum%(int)number.size()!=0)
{
break;
}
int count=0;
for (size_t j=0;j<number.size();j++)
{
if (number[j]>aver)
{
count+=number[j]-aver;
}
}
setcount.push_back(count);
}
for (int i=0;i<(int)setcount.size();i++)
{
cout<<"Set #"<<i+1<<endl;
cout<<"The minimum number of moves is "<<setcount[i]<<".\n"<<endl;
}
}
