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使用Dom解析xml

    一.理论准备                 二.上代码  <?xml version="1.0" encoding="utf-8" ?> < ...

  2. LibLinear(SVM包)的MATLAB安装

    LibLinear(SVM包)的MATLAB安装 1 LIBSVM介绍 LIBSVM是众所周知的支持向量机分类工具包(一些支持向量机(SVM)的开源代码库的链接及其简介),运用方便简单,其中的核函数( ...

  3. UIKIT网页基本结构学习

    没办法,哈哈,以后一段时间,如果公司没有招到合适的运维研发, 啥啥都要我一个人先顶上了~~~:) 也好,可以让人成长. UIKIT,BOOTSTRAP之类的前端,搞一个是有好处的,我们以前即然是用了U ...

  4. go网络编程示例,客户端,服务器端

    http://blog.csdn.net/wangningyu/article/details/22859245 http://blog.csdn.net/wangningyu/article/det ...

  5. 用sql增、修改、删除字段

    --给一个表增加一个字段 ); --给一个表修改一个字段的数据类型 ,); --通用sql修改字段的用法 ,); --删除一个字段 alter table wm_goods drop column b ...

  6. 17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量

    17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量 下面的章节包含信息关于mysql ...

  7. XtraForm中更换皮肤

    前提: 默认皮肤的显示http://www.cnblogs.com/chucklu/p/4785572.html 1.修改XtraForm的LookAndFeel的SkinName属性,设置为Cara ...

  8. PHP 'ext/soap/php_xml.c'不完整修复多个任意文件泄露漏洞

    漏洞版本: PHP 5.4.1 PHP 5.3.13 PHP 5.3.12 PHP 5.3.11 PHP 5.3.10 PHP 5.3.1 PHP 5.3 漏洞描述: BUGTRAQ ID: 6237 ...

  9. 将eclipse新建项目的默认编码GBK改为UTF-8

    在eclipse下: 新建项目默认编码设置:Window->Preferences->General->Workspace->Text file encoding 将其改为UF ...

  10. Ubuntu全新系统一些配置

    0.安装JDK,http://www.oracle.com/technetwork/java/javase/downloads/index.html 1.安装Intellij IDEA,https:/ ...