Box of Bricks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 19949   Accepted: 8029

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

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

Sample Output

  1. Set #1
  2. The minimum number of moves is 5.

Source

Southwestern European Regional Contest 1997

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int n,i,s,aver,a[51],num,j=0;
  5. while(~scanf("%d", &n))
  6. {
  7. if(n == 0) break;
  8. j++,s = 0,num = 0;
  9. for(i = 0; i < n; i++)
  10. {
  11. scanf("%d", &a[i]);
  12. s+=a[i];
  13. }
  14. aver= s/n;
  15. for(i = 0; i < n; i++)
  16. if(a[i] > aver)
  17. num = num + a[i] - aver;
  18. printf("Set #%d\nThe minimum number of moves is %d.\n\n", j, num);
  19. }
  20. return 0;
  21. }

POJ 1477: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. 591 - Box of Bricks

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

  7. Box of Bricks

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

  8. HDU 2088 Box of Bricks

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

  9. HDU 2088 Box of Bricks(脑洞)

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

随机推荐

  1. jquery data属性 attr vs data

    html5的自定义data属性相信大家都不会陌生,有了它你可以绑定所需的数据到指定元素上.然后通过jquery设置.获取数据,简直开心的不行啊.想到设置.获取元素属性值,大家一定首先想到了jquery ...

  2. UVA 1995 I can guess the structer

    模 拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #inclu ...

  3. 【Eclipse+IntelliJ反编译】Eclipse/IntelliJ IDEA反编译查看源码及注释

    怎么用IDE查看第三方jar包的源码和注释,IntelliJ IDEA自带反编译器,Eclipse装个插件即可,不能看注释就麻烦了,总不能去找API文档吧,现在终于掌握了,下面给出解决方案,供大家参考 ...

  4. AOJ -0033 Ball(DFS)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=22516 一道需要思考的搜索题. 题意:十个球按给定顺序从图中所示容器中下落, ...

  5. 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组

    1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组   #include <iostream> #include <string> #include & ...

  6. ACM组队安排-——杭电校赛(递推)

    #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #in ...

  7. NTKO在线office控件使用实例

    目录 1. NTKO在线office控件使用实例 1.1. 基础介绍 1.2. 基本原理 1.3. 实例 1.3.1. 打开.保存部分代码 1.3.2. 动态设值 1. NTKO在线office控件使 ...

  8. 2014-8-21的一次性能诊断--应用server瓶颈

    今天现场实施反馈系统总体慢.已经接到用户许多的投诉,要求现场发回weblogic日志和Oracle 数据库报告.简要说下系统的架构:典型的B/S三层架构,开发语言是java,中间件用的是weblogi ...

  9. seajs入门使用

    使用 Sea.js 进行模块化开发还能够带来非常多优点: 模块的版本号管理. 通过别名等配置,配合构建工具,能够比較轻松地实现模块的版本号管理. 提高可维护性.模块化能够让每一个文件的职责单一,很有利 ...

  10. man中文手册

    Ubuntu安装man手册 sudo apt-get install manpages-zh CentOS安装man手册 yum install man man中文安装包 yum install ma ...