Box of Bricks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 24101   Accepted: 9378

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 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.

Source

Poj1477的更多相关文章

  1. [POJ1477]Box of Bricks

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19503   Accepted: 7871 Description Litt ...

  2. poj1477(水)

    犯了一个错误,贡献了一次CE: G++里面没有头文件,用scanf会CE:然而C++就可以. 两大cow解释: 最好不要c 的输入和c++的一起用 (特别是关同步的时候) 然而好像他们也不是很了解.. ...

  3. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. python3的socket使用

    如果需要设置两台机器的端口,请查看博文 centos7开放端口和防火墙设置 需要实现两台机器的信息交互,使用 socket 进行调度.其中服务端为: #!/usr/bin/env python # - ...

  2. Django-restframework 之认证源码分析

    Django-restframework 源码分析之认证 前言 最近学习了 django 的一个 restframework 框架,对于里面的执行流程产生了兴趣,经过昨天一晚上初步搞清楚了执行流程(部 ...

  3. DSAPI中TCP、UDP、HTTP的选择

    在DSAPI中,网络通讯主要有以下几种:1 [TCP] TCP服务端 TCP客户端 2 [UDP] UDP服务端 UDP客户端 UDP指令版服务端 UDP指令版客户端 3 [HTTP] HTTP服务端 ...

  4. MVC页面扩展方法 单例模式

    MVC页面扩展方法    单例模式    /// <summary>         /// 创建一个Config内容对象         /// </summary>     ...

  5. webapi 跨域问题

    参考:http://www.cnblogs.com/chenxizhang/p/3821703.html 给自己做个笔记 HttpContext.Current.Response.AddHeader( ...

  6. forEach循环对集合进行循环时,需判断是否为null;

    分析forEach的源码会发现:foreach源码例子: public class Foreach { public static void main(String[] args) { List< ...

  7. boostrap中模态框显示在阴影之下

    boostrap中模态框显示在阴影之下 出现这种情况的原因我开始也搞了很久,问题出现在哪里呢? 有事问百度,在百度上查了一下资料,他们主要的解决办法:是 修改标签的z-index属性的值, 我试着改了 ...

  8. Dotspatial 要素重叠部分去除

    private void toolStripButton32_Click(object sender, EventArgs e) { /重叠部分去除操作——测试成功 if (mapMain.Layer ...

  9. Android之PhotoView使用

    文章大纲 一.什么是PhotoView二.代码实战三.项目源码下载 一.什么是PhotoView   一款 ImageView 展示框架,支持缩放,响应手势,位于图片排行榜的第五位,PhotoView ...

  10. Android Glide详细使用教程

    此处我只是做个记录,后边再补充 原文地址:http://www.jufanshare.com/content/35.html 这篇文章写的比较清楚,还附有Demo代码.算是不错的Android Gli ...