MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

题目地址:
         http://acm.hdu.edu.cn/showproblem.php?pid=2088
题目描述:

Problem 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 consideration, 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, print the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line between each set.

Sample Input
6
5 2 4 1 7 5
0

Sample Output
5

题目分析:
         哈哈 ,又是一个水题,  貌似这段时间一直在水题.  刚开始看的时候还以为是 DP ,  看懂题目后知道这只是一个简单的小学数学题,呵呵.   如果求移动步数还复杂点, 但题目要求的是 最小搬动次数, 那么只要求出平均值, 大于平均值的墙就是要移动的墙 ,累加就可以了.

代码如下:

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int N;
    int f = 0;
    while ( cin >> N, N )
    {
            if ( f )
            {
                 cout << endl; 
            }
            f = 1;
            int num[N+1];
            num[N] = 0;
            for ( int i = 0; i != N; ++ i ) 
            {
                  cin >> num[i];
                  num[N] += num[i]; 
            }
            num[N] /= N;
            int nCount = 0;
            for ( int i = 0; i != N; ++ i )
            {
                  if ( num[i] > num[N] )
                  {
                       nCount += num[i] - num[N]; 
                  } 
            } 
            cout << nCount << endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/MiYu/archive/2010/08/18/1802476.html

HDOJ HDU 2088 Box of Bricks ACM 2088 IN HDU相关推荐

  1. HDU 2088 Box of Bricks

    解题报告:求要将所有的墙弄成一样的高度最少需要移动多少块砖,水题.不过还要注意一下格式,是两个实例时间有空行,不是每个测试数据后面都有空行. 1 #include<cstdio> 2 in ...

  2. HDOJ 1874 HDU 1874 畅通工程续 ACM 1874 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1874 ...

  3. HDOJ 1213 HDU 1213 How Many Tables ACM 1213 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1213 ...

  4. HDOJ 1016 HDU 1016 Prime Ring Problem ACM 1016 IN HDU

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1016 题目描述: Prime Ring Problem Time Limit: 4000/2000 ...

  5. HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目描述: ...

  6. HDOJ HDU 2058 The sum problem ACM 2058 IN HDU

    //MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 :          http://acm.hdu.edu.cn/showproblem.php?pid=2 ...

  7. HDOJ 1247 HDU 1247 Hat’s Words ACM 1247 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址 : http://acm.hdu.edu.cn/showproblem.php?pid=1247 题目描述: ...

  8. HDOJ 1875 HDU 1875 畅通工程再续 ACM 1875 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1875 ...

  9. HDOJ 1286 HDU 1286 找新朋友 ACM 1286 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目描述:          http://acm.hdu.edu.cn/showproblem.php?pid=1286 ...

最新文章

  1. 运维的shell小编(1)
  2. SparkStreaming官方示例程序运行方式
  3. InnoDB行锁的实现分析
  4. CSS3学习系列之颜色
  5. 超图桌面版开发入门图解
  6. NTU 课程笔记 7454 GAN
  7. Java中设计模式之单例设计模式-1
  8. CIO客观评价SAP和用友的差异
  9. 谈搜索架构师的不同阶段
  10. JAVA通信编程(五)——串口通讯的补充说明
  11. java list 自定义类型转换_使用Java Stream API将List按自定义分组规则转换成Map的一个例子...
  12. NCRE四级网络工程师考题详解----对等计算模型(P2P)
  13. 使用sql2005的新特性分页的储存过程:Top,Row_Number
  14. flex 学习笔记 皮肤(一)
  15. 面试遇到职场PUA,只能说兄弟你还嫩了点
  16. java tar压缩工具类_分享apache的commons-compress的TarUtils压缩工具类对文件数据进行加解密、解析及格式化校验等操作...
  17. matlab fspecial disk,Matlab fspecial 用法详述,附示例
  18. 在matlab中的polyval函数,Python/Numpy中三输出等价的Matlab polyval函数
  19. PLC系统调试的步骤
  20. 低维空间到高维空间的映射

热门文章

  1. APE到底比MP3文件“好听”多少
  2. linux grub内核选择,UBUNTU GRUB没有内核选项,怎么回事啊?
  3. java io类型_Java NIO之Java中的IO分类
  4. mysql decimal被四舍五入_MySQL之ROUND函数四舍五入的陷阱
  5. svn拒绝访问是什么原因_为什么Windows无法访问U盘|电脑U盘被拒绝访问
  6. syslog(LOG_ERR, Error: errcode=%d, message=%s, errcode, errmsg);
  7. STM32 AES 加解密流程梳理
  8. 三星安卓4.2手机微信字体缺陷:“兹崖幽噩弱器朋鹏网品晶磊弼” ttf 字体缺失,安卓 4.2.2 微信 6.5.4...
  9. 鼓励玩家自创,大量的UGC能为手游续命吗?
  10. c#和c++互操作(平台调用相关)