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. Linux简介及Ubuntu安装

    Linux简介及Ubuntu安装 常见指令 系统管理命令 打包压缩相关命令 关机/重启机器 Linux管道 Linux软件包管理 vim使用 用户及用户组管理 文件权限管理 大牛笔记-www.weix ...

  2. javascripct数组

    定义数组 数组对象用来在单独的变量名中存储一系列的值. 我们使用关键词 new 来创建数组对象.下面的代码定义了一个名为 myArray 的数组对象: var myArray=new Array() ...

  3. 前端资源多个产品整站一键打包&包版本管理(三)—— gulp分流

    问题: 当我们一个工作台里面有好几个项目的时候,我们要为项目的前端资源进行打包,但是,gulpfile只有一个,如果我们把所有的打包都放在同一个文件里面,首先文件会越来越大,而且不便于管理,这时,我们 ...

  4. -----IT男生涯————初始篇

    大家好,我是kuuga,一名普通大学的在读生.其实,当时我不知道为什么会选择计算机这个学院,而且还选择了网络工程这个坑爹的专业.为什么说坑爹呢?因为几年学生生涯中编程已经占了很多时间和课程,至于我的专 ...

  5. grep线上环境精典案例后续

    请执行命令取出 linux 中 eth0 的 IP 地址(请用 cut,有能力者也可分别用 awk,sed 命令答). 自己的方法: [root@nginx_back ~]# ifconfig eth ...

  6. AngularJS的使用方法

    1.第一个ng demo <div ng-app="" ng-init="name='Kevin'"> <input ng-model=&qu ...

  7. Python的传值和传址与copy和deepcopy

    1.传值和传址 传值就是传入一个参数的值,传址就是传入一个参数的地址,也就是内存的地址(相当于指针).他们的区别是如果函数里面对传入的参数重新赋值,函数外的全局变量是否相应改变,用传值传入的参数是不会 ...

  8. c++ 重定位输出到DOS

    #define USE_WIN32_CONSOLE int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTST ...

  9. js 拼接 三列做为一行

    function Ajax_GetCourseAndResource(data) { $(".ol-course-list").empty(); var html = " ...

  10. poj 3373 Changing Digits (DFS + 记忆化剪枝+鸽巢原理思想)

    http://poj.org/problem?id=3373 Changing Digits Time Limit: 3000MS   Memory Limit: 65536K Total Submi ...