Box of Bricks


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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?

Input 

The input consists of several data sets. Each set begins with a line containing the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1 <= n <= 50 and 1 <= hi <= 100.

The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.

The input is terminated by a set starting with n = 0. This set should not be processed.

Output 

For each set, first print the number of the set, as shown in the sample output. Then print the line ``The minimum number of moves is k.'', where k is the minimum number of bricks that have to be moved in order to make all the stacks the same height.

Output a blank line after each set.

Sample Input 

6
5 2 4 1 7 5
0

Sample Output 

Set #1
The minimum number of moves is 5.

注意格式。

 #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(){
int n, t, sum, cnt, average, k = ;
vector<int> v;
while(cin >> n){
if(n == )
break;
v.clear();
sum = ;
cnt = ;
for(int i = ; i < n; i++){
cin >> t;
v.push_back(t);
sum += t;
}
average = sum / v.size();
for(int i = ; i < v.size(); i++){
if(v[i] > average){
cnt += (v[i] - average);
}
}
cout << "Set #" << k++ << endl;
cout << "The minimum number of moves is " << cnt << "." << endl;
cout << endl;
}
//system("pause");
return ;
}

zoj 1251 Box of Bricks的更多相关文章

  1. ZOJ Problem Set - 1251 Box of Bricks

    这道题简单的翻译成纯数学语言就是给你n个数字,每次运算只能是加1或者减1,问经过最短几步可以使得n个数字相等 由于题目限定了n个数字一定有平均数,所以求出avg,将所有比其大的数字或者比其小的数字的差 ...

  2. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. Box of Bricks最小移动砖块数目

    Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...

  4. [POJ1477]Box of Bricks

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19503   Accepted: 7871 Description Litt ...

  5. HDOJ(HDU) 2088 Box of Bricks(平均值)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  6. HDOJ 1326 Box of Bricks(简单题)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  7. 591 - Box of Bricks

     Box of Bricks  Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...

  8. Box of Bricks

    Box of Bricks Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  9. HDU 2088 Box of Bricks

    http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...

随机推荐

  1. [在读]Nodejs实战

    书到手的时候其实就已经过时,Express更新太快,因而书中的例子实践起来会有很多阻碍. 目前搁置状态.

  2. IDEA代码注释<斜体>的解决方法

    打开设置 将上图的checkbox取消勾选即可.

  3. mvc报( 检测到有潜在危险的 request.form 值 )错的解决方案

    今天在做项目中遇到了报( 检测到有潜在危险的 request.form 值 )错,百度过后解决了该问题,出此问题主要还是因为提交的Form中有HTML字符串,例如你在TextBox中输入了html标签 ...

  4. redis过期事件

    背景:目前在商城项目,订单有过期逻辑,小伙伴提议用redis做,经讨论分析,redis有key的过期事件,貌似可以实现,但是咨询大神,好像不建议这样用,可能会丢数据 随便写了段python代码测试 i ...

  5. 【转】java序列化一定要应该注意的6个事项!

    1.如果子类实现Serializable接口而父类未实现时,父类不会被序列化,但此时父类必须有个无参构造方法,否则会抛InvalidClassException异常. 2.静态变量不会被序列化,那是类 ...

  6. qt read excel

    void exceladapter::readfile(QString filename, QString sheetname, int colNo){ QSqlDatabase db = QSqlD ...

  7. Android一键锁屏APP

    题记: 这个app完全是拾人牙慧,作为练手用的,其实没有什么原创的东西.当然,博客还是我自己写的,记录下来,对自己也算是一种成长吧. 转载请注明原文地址: http://www.cnblogs.com ...

  8. vue-devtools在google浏览器下安装扩展

    下载vue-devtools,地址: https://github.com/vuejs/vue-devtools 解压到对应目录,eg: D:\ProgramFiles\vue-devtools-de ...

  9. vim下ctrl + s 僵死问题的解决

    vim下ctrl + s 僵死问题的解决 vim  使用vim习惯性手残Ctrl+S ,解决方法 : Ctrl + Q 就能恢复了

  10. 洛谷 P1216 [USACO1.5]数字三角形 Number Triangles(水题日常)

    题目描述 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 5 ...