POJ 1477 Box of Bricks
2013-05-03 21:09
357 查看
Box of Bricks
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++]
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 15765 | Accepted: 6584 |
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; }
相关文章推荐
- poj 1477 Box of Bricks
- POJ 1477 Box of Bricks
- poj 1477 Box of Bricks
- poj1477 box of bricks
- POJ 1477 && HDU 1326 Box of Bricks(水~)
- poj 1477 Box of Bricks
- (贪心5.2.8)POJ 1477 Box of Bricks
- 1477 Box of Bricks
- pku 1477 Box of Bricks
- PKU 1477 Box of Bricks
- POJ 1477:Box of Bricks
- hdu 1326 Box of Bricks
- Uva 591 Box of Bricks
- Box of Bricks
- HDOJ 2088 Box of Bricks
- HDU 1.2.2 Box of Bricks
- 591 - Box of Bricks
- virtual hust 2013.6.23 数学杂题基础题目 F - Box of Bricks
- zoj 1251 Box of Bricks
- 杭电 acm Box of Bricks