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

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

THINKING

  贪心,先计算平均值,再扫描数组求出差值,注意句末的句号和组数之间的空行!

var a:array[..] of longint;
n,i,sum,summ,t:longint;
begin
summ:=;
while true do
begin
fillchar(a,sizeof(a),);
sum:=;
t:=;
readln(n);
if n= then halt;
for i:= to n do
begin
read(a[i]);
inc(sum,a[i]);
end;
sum:=sum div n;
for i:= to n do
t:=abs(sum-a[i])+t;
writeln('Set #',summ);
writeln('The minimum number of moves is ',t div ,'.');
writeln;
inc(summ);
end;
end.

[POJ1477]Box of Bricks的更多相关文章

  1. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. Box of Bricks最小移动砖块数目

    Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...

  3. HDOJ(HDU) 2088 Box of Bricks(平均值)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  4. HDOJ 1326 Box of Bricks(简单题)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  5. 591 - Box of Bricks

     Box of Bricks  Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...

  6. Box of Bricks

    Box of Bricks Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  7. HDU 2088 Box of Bricks

    http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...

  8. HDU 2088 Box of Bricks(脑洞)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...

  9. zoj 1251 Box of Bricks

    Box of Bricks Time Limit: 2 Seconds      Memory Limit: 65536 KB Little Bob likes playing with his bo ...

随机推荐

  1. javascript函数基础

    Function类型 由于函数是对象,因此函数名实际上是一个指向函数对象的指针,不会与函数绑定 所以没有重载这个概念!!!!!!!!!!!!!!!!!!!!!!!!!! function sum1() ...

  2. 前端资源多个产品整站一键打包&包版本管理(四)—— js&css文件文件打包并生成哈希后缀,自动写入路径、解决资源缓存问题。

    问题: 当我们版本更新的时候,我们都要清理缓存的js跟css,如何使得在网页中不需要手动清理呢? 答案: 生成带有哈希后缀的js跟css文件 1.文件路径 路径中的conf.js 是用于放置全局打包的 ...

  3. .net faq

    http://www.indiabix.com/technical/dotnet/ http://www.codeproject.com/Articles/637480/Csharp-and-ASP- ...

  4. Bootstrap简易使用指南

    1.框架 1.1全局样式 使用HTML5的doctype,scaffolding.less中定义全局样式,从2开始使用normalize.css,并使用reset.less进行简化 1.2默认栅格系统 ...

  5. 使用ssh公钥实现免密码登录

    使用ssh公钥实现免密码登录 ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(10.207.160.34),B(10 ...

  6. [转载]常用Web Service汇总(天气预报、时刻表等)

    下面总结了一些常用的Web Service,是平时乱逛时收集的,希望对大家有用. ============================================ 天气预报Web Servic ...

  7. Linux下 config/configure/Configure、make 、make test/make check、sudo make install 的作用

    转自Linux下 config/configure/Configure.make .make test/make check.sudo make install 的作用 这些都是典型的使用GNU的AU ...

  8. Spring+MyBatis实践—工程配置

    初次实践:Spring+MyBatis技术搭建框架,采用Bootstrap前端开源框架. 简介: MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除 了几乎所 ...

  9. 一组神奇的 3D Gif 动图

    本文由 极客范 - 黄利民 翻译自 mymodernmet.欢迎加入极客翻译小组,同我们一道翻译与分享.转载请参见文章末尾处的要求. 虽然 gif 动图/动画似乎是无处不在现在了,但有些聪明人已经把 ...

  10. 1090-Rock, Paper, Scissors

    描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...