Box of Bricks 

Little Bob likes playing with his box of bricks. He puts the bricks one upon another and buildsstacks of different height. ``Look, I've built a wall!'', he tells his older sister Alice. ``Nah, you shouldmake 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 allstacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimumnumber 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 stacksBob has built. The next line contains
n numbers, the heights
h
i of the
n stacks. You may assume
and
.

The total number of bricks will be divisible by the number of stacks. Thus, it is always possibleto 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 thathave to be moved in order to make all the stacks the same height.

Output a blank line after each set.

Sample Input

  1. 6
  2. 5 2 4 1 7 5
  3. 0

Sample Output

  1. Set #1
  2. The minimum number of moves is 5.
  1. #include<stdio.h>
  2. int main(void)
  3. {
  4. int n,i,count=1;
  5. while(scanf("%d",&n)&&n)
  6. {
  7. int h,k=0,sum=0,a[100]={0};
  8. for(i=0;i<n;i++)
  9. {scanf("%d",&a[i]);sum+=a[i];}
  10. h=sum/n;
  11. for(i=0;i<n;i++)
  12. if(a[i]>h)
  13. k+=a[i]-h;
  14. printf("Set #%d\nThe minimum number of moves is %d.\n\n",count++,k);
  15. }
  16. return 0;
  17. }

591 - 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. [POJ1477]Box of Bricks

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

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

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

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

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

  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. 查看死锁原因 /data/anr/traces.txt

    Android ANR这个错误大家并不陌生,但是从Android 2.2开始出错的ANR信息会自动上传给Google进行系统分析改进,当然了你的应用ANR错误其实保存在一个文件中,在/data/anr ...

  2. [转]给Linux系统管理员准备的Nmap命令的29个实用范例+ tsysv 系统服务器管理器

    原文链接:http://os.51cto.com/art/201401/428152.htm Nmap即网络映射器对Linux系统/网络管理员来说是一个开源且非常通用的工具.Nmap用于在远程机器上探 ...

  3. printf格式控制详解

    format 参数输出的格式,定义格式为 %[flags][width][.precision][length]specifier specifier在最后面.定义了数据类型. Where the s ...

  4. Android 程式开发:(廿一)消息传递 —— 21.3 使用Intent发送短信

    使用SmsManager类,可以在自己编写的程序内部发送短信,而不需要调用系统的短信应用. 然而,有的时候调用系统内置的短信应用会更加方便. 这时,需要使用一个MIME类型为vnd.android-d ...

  5. windows下apache如何完整卸载?

    1.运行services.msc,在服务中停止 apache 服务.2.运行命令行程序,输入 sc delete apache,删除该服务3.删除apache文件夹.

  6. log翻硬币

    若果有一组硬币,(假定有十个),每一个硬币仅仅有两个面,正面用以表示.反面用零表示. 给定目标(初始状态)1111100000 正正正正正反反反反反 (目标状态)   1000011101 正反反反反 ...

  7. windows api 梳理

    PathMatchSpec Function Searches a string using a Microsoft MS-DOS wild card match type. Syntax BOOL  ...

  8. CIconListBox带图标的列表框类

    有时候,我们需要在列表框ListBox中插入带图标的文字项,这就需要自己派生一个类出来了,网上的一个CIconListBox类还不错,网站http://www.codeguru.com/Cpp/con ...

  9. hdu1200(来来回回串起来)

    Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secret ...

  10. TCanvas.CopyRect方法中参数CopyMode的意义

    首先看可能取值: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 cmBlackness = BLACKNESS; cmDstInvert = DSTINVERT; cmMer ...