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. poj1815Friendship(最小割求割边)

    链接 题意为去掉多少个顶点使图不连通,求顶点连通度问题.拆点,构造图,对于<u,v>可以变成<u2,v1> <v2,u1>容量为无穷,<u1,u2>容量 ...

  2. Java GC基础

    Java的垃圾回收机制负责回收无用对象占据的内存资源,但是有特殊情况:假定对象不是使用new关键字获得了一块儿“特殊”的内存区域,

  3. FPGA原型验证

    为什么要做FPGA原型验证? FPGA原型验证可以在IC流片前对芯片功能和性能做出评估,同时,可以给软件设计人员提供验证平台.所有的设计,无论是SOC还是ASIC都需要被验证(功能和时序验证),以确保 ...

  4. /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

    [root@localhost nagios]# make install-webconf/usr/bin/install -c -m 644 sample-config/httpd.conf /et ...

  5. IOS之pageControl

    用户点击页面控件,会触发UIControlEventValueChanged事件,并启动设置为控件动作的任何方法.可以通过调用currentPage查询控件的新值,并通过调整numberOfPages ...

  6. RHEL5.8上SAMBA源码修改打包安装流程

    之前一直使用系统自带的SAMBA,近期需要对SAMBA代码做一些修改,然后还是打算用RPM包的方式来安装部署. 这个流程本身不复杂,在这里记录下来,免得在另外写说明文档. 关键词:RHEL5.8, s ...

  7. django 模板中{%for%}的使用

    1.{%for athlete in list reversed%}  reversed用于反向迭代 2.for 标签 支持一个可选的 empty 变量 3.forloop 模板变量 4.forloo ...

  8. resnet.caffemodel

    http://blog.csdn.net/baidu_24281959/article/details/53203757

  9. 工作流activi链接地址

    http://topmanopensource.iteye.com/blog/1313865

  10. ajax 请求json数据中json对象的构造获取问题

    前端的界面中,我想通过ajax来调用写好的json数据,并调用add(data)方法进行解析,请求如下: json数据如下: { “type”:"qqq", "lat&q ...