您的位置:首页 > 其它

POJ 1477 Box of Bricks

2013-05-03 21:09 357 查看
Box of Bricks

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 15765Accepted: 6584
Description

Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. "Look, I've built a wall!", he tells his older sister Alice. "Nah, you should make all stacks the same height. Then you would have a real wall.", she retorts. After a little con- sideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help?[C++]

#include<iostream>

using namespace std;

int main()
{
int x=0,n,num[50];
while(cin>>n)
{
int sum=0;
if(n==0)
break;
x++;
for(int i=0;i<n;i++)
{
cin>>num[i];
sum+=num[i];
}
int average=sum/n;
sum=0;
for(int i=0;i<n;i++)
{
if(num[i]>average)
sum+=num[i]-average;
}
cout<<"Set #"<<x<<endl;
cout<<"The minimum number of moves is "<<sum<<"."<<endl<<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: