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. 500 Keyboard Row 键盘行

    给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. 详见:https://leetcode.com/problems/keyboard-row/description/ C++: cl ...

  2. Apache Kylin Cube 的存储

    不多说,直接上干货! 简单的说Cuboid的维度会映射为HBase的Rowkey,Cuboid的指标会映射为HBase的Value. Cube映射成HBase存储 如上图原始表所示:Hive表有两个维 ...

  3. Asp.net 字符(一)

    1.字母大小写处理 private string GetChangedStr(string oldStr, strType type) { string newStr = ""; ...

  4. 转 Java 208道面试题及部分答案 补充部分答案

    转自https://www.cnblogs.com/chen1005/p/10481102.html   ---恢复内容开始--- 一.Java 基础 1.JDK 和 JRE 有什么区别? 答:JRE ...

  5. T4312 最大出栈顺序

    题目描述 给你一个栈和n个数,按照n个数的顺序入栈,你可以选择在任何时候将数 出栈,使得出栈的序列的字典序最大. 输入输出格式 输入格式: 输入共2行. 第一行个整数n,表示入栈序列长度. 第二行包含 ...

  6. VUE学习——vue的内部指令学习(趁自己没忘,学习记录一下)

    1.v-if&v-else&v-show v-if用来判断是否加载html的DOM,v-if和v-else一般是一起用的. v-show相当于display,DOM已经加载出来了,这个 ...

  7. Android利用融云做异地登录提醒

    在RongCloudEvent下找到onChanged方法 @Override public void onChanged(ConnectionStatus connectionStatus) { s ...

  8. hdu 5402 Travelling Salesman Problem (技巧,未写完)

    题意:给一个n*m的矩阵,每个格子中有一个数字,每个格子仅可以走一次,问从(1,1)走到(n,m) 的路径点权之和. 思路: 想了挺久,就是有个问题不能短时间证明,所以不敢下手. 显然只要n和m其中一 ...

  9. 使用ABAP正则表达式解析HTML标签

    需求就是我用ABAP的某个函数从数据库读取一个字符串出来,该字符串的内容是一个网页. 网页的form里包含了很多隐藏的input field.我的任务是解析出name为svyValueGuid的inp ...

  10. VTK教程系列:VTK基础及应用开发教程

    由于OpenCV不能使用,只能使用VTK库的图像处理库,暂时还没有找到其他可以全面替代的库: CSDN东灵工作室:http://blog.csdn.net/www_doling_net/article ...