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. Word删除空白页

    1.常见的就是在前一页最后按delete 2.我遇到的问题是,共两页第一页是平常的A4,是表格,第二页也是A4,只不过横着显示(后来才知道的),中间是分节符,不能直接删除的,否则表格各个部分分开在好几 ...

  2. javascript mvc

    http://www.webjx.com/javascript/jsajax-15996.html http://blog.csdn.net/jjfat/article/details/7963608 ...

  3. Ubuntu修改语言环境为英文

    转自把语言环境变量改为英文 将Ubuntu系统语言环境改为英文的en_US.UTF-8 查看当前系统语言环境 locale 编辑配置文件,将zh_US.UTF-8改为en_US.UTF-8,zh改为e ...

  4. GITLAB的版本回退(非命令行)

    今天遇到小韩的问题,大约解决如下:

  5. BOM的来源是不可能出现的字符,GB2312双字节高位都是1,Unicode理论的根本缺陷导致UTF8的诞生

    Unicode字符编码规范   http://www.aoxiang.org 2006-4-2 10:48:02Unicode是一种字符编码规范 . 先从ASCII说起.ASCII是用来表示英文字符的 ...

  6. nginx优化 突破十万并发(转)

    一.一般来说nginx 配置文件中对优化比较有作用的为以下几项: 1. worker_processes 8; nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu计 ...

  7. selectpicker下拉多选框ajax异步或者提前赋值=》默认值

    Bootstrap select多选下拉框赋值 success: function (data) { var oldnumber = new Array(); $.each(data, functio ...

  8. jQuery zTree v3.5 实例3 异步树

    最终效果: 点击非叶子节点时,向后台发送请求,获取下级菜单 前台代码如下: <%@ page language="java" contentType="text/h ...

  9. Java中int与Integer

    一般小写字母开头的是数据类型(如int double),大写字母开头的一般是封装为类(如Double),里面有很多方法,比如实行转换Integer.parseInt(arg0),可以把其他类型的数据转 ...

  10. mysql 限制并发select patch

    限制并发select的patch,代码量很少,主要是为了学习mysql的源码,yy一下. 增加两个全局控制变量: thread_limit_min thread_limit_max 增加一个条件变量: ...