Box of Bricks

Time
Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 14836    Accepted Submission(s):
4912

Problem 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 consideration, 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, print the minimum number of bricks that
have to be moved in order to make all the stacks the same height.
Output a
blank line between each set.
 
Sample Input
6
5 2 4 1 7 5
0
 
Sample Output
5

HDU2088JAVA的更多相关文章

随机推荐

  1. java向文件写数据的3种方式

    下边列举出了三种向文件中写入数据的方式,当然还有其他方式,帮助自己理解文件写入类的继承关系.类的关系: file->fileoutputstream->outputstreamWriter ...

  2. 李洪强iOS开发之-环信02.2_环信官网下载环信 SDK

    李洪强iOS开发之-环信02.2_环信官网下载环信 SDK 移动客服即时通讯云 iOS SDK 当前版本:V3.1.4 2016-07-08 [ 版本历史 ] | 开发指南 | 知识库 | Demo源 ...

  3. mysql日志的查看与开启

    mysql的日志类型: 错误日志: log-error 查询日志: log 慢查询日志: log-slow-queries 更新日志: log-update 二进制日志: log-bin 开启错误日志 ...

  4. lubuntu安装maven

    原文转自:jobar.iteye.com/blog/1776747 1 apt-cache search maven 获取所有可用的maven包 2 sudo apt-get install mave ...

  5. 三星 PMU NXE2000,x-powers的AXP228,NXE2000

    核心板PMIC X4418CV2并没有用三星推荐的PMU NXE2000,而是自主研发,采用x-powers的AXP228,这是因为AXP228更符合用户的习惯,更适合做产品,他们有如下区别: PMU ...

  6. git ignore 的使用

    http://www.barretlee.com/blog/2015/09/06/set-gitignore-after-add-file/ 需要注意的 **: 如果一个 pattern 以 ** 开 ...

  7. check约束条件

    --约束:对列的值起一个约束性的作用,规定列的值的范围 --主键.外键.非空.自增长标识列.唯一列(unique).check约束 --check 约束 --在某个表里点击右键→设计→进去找到要约束的 ...

  8. 如何实现Azure虚拟网络中点到站VPN的自动重连

     在Windows Azure早期版本中,用户要在某台Azure平台之外的机器与Azure平台内部的机器建立专用连接,可以借助Azure Connect这个功能.当前的Azure版本,已经没有Az ...

  9. HDU-2521 反素数

    反素数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  10. 逐行返回http响应的内容

    前言 问题:1.什么是特殊字符? 2.为什么要处理特殊字符? 答:特殊字符指相对于传统或常用的符号外,使用频率较少字符且难以直接输入的符号,比如数学符号:单位符号:制表符等 有些符号在URL中是不能直 ...