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. Android 获取SDCard上图片和视频的缩略图

    获取图片缩略图和视频缩略图的方法: Java代码: import java.io.File; import android.app.Activity; import android.graphics. ...

  2. Super Phyllis(穷举+搜索)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2723 题意:给出一些字符串u,v,代表u-&g ...

  3. Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  4. 实验记录贴 —— 账号同步实验 RTX 和 LDAP(AD域)

    目前,公司有多个系统,RTX,邮箱(MD),OA,NC. 这些系统之间,如果要实现单点登录的话,账户肯定需要同步,或者某一种映射机制. 如果所有数据都和中央账号数据库(LDAP,这里是AD域)看齐,那 ...

  5. HDOJ --- 1159 Common Subsequence

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  7. MFC中添加OpenGL

    WINDOWS下展示OpenGL有多种形式: MFC 或 win32,该如何向MFC中添加OpenGL?下面是介绍最简单OpenGL框架. 1.首先通过VS建立MFC应用程序-MyOpenGL,选择单 ...

  8. UVa10895 Placing Lampposts

    UVa10895 Placing Lampposts 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34290 [思路] ...

  9. 《University Calculus》-chape6-定积分的应用-求体积

    定积分一个广泛的应用就是在求解一些“看似不规则”的几何体的体积,之所以说看似不规则,是因为不规则之下还是有一定的“规则性”可言的,我们就是需要抓住这些线索进行积分运算得到体积. 方法1:切片法. 这里 ...

  10. 【转】shell 教程——02 几种常见的Shell

    上面提到过,Shell是一种脚本语言,那么,就必须有解释器来执行这些脚本. Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等,习惯上把它们称作一种Shell.我们常说 ...