Box of Bricks

原创 2013年12月29日 20:15:49

水题一道。。无需多说。。一切尽在代码中。。

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 containsn numbers, the heights hi of the n stacks. You may assume $1 Ÿ\le n \leŸ 50$ and $1 \leŸ h_i Ÿ\le 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.

#include <stdio.h>
int main()
{
    int n, i, s, aver, a[51], num, j = 0;
    while(scanf("%d", &n)!=EOF)
    {
        if(n == 0) break;
        j++;
        s = 0;
        num = 0;
        for(i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            s = s + a[i];
        }
        aver = s / n;
        for(i = 0; i < n; i++)
        {
            if(a[i] > aver)
                {
                    num = num + a[i] - aver;
                }
        }
        printf("Set #%d\nThe minimum number of moves is %d.\n\n", j, num);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

第三次训练 Box of Bricks

Box of Bricks  Little Bob likes playing with his box of bricks. He puts the bricks one ...
  • u013022160
  • u013022160
  • 2013年12月17日 23:49
  • 377

Box of Bricks ——平均数问题

Box of Bricks  Little Bob likes playing with his box of bricks. He puts the bricks one ...
  • A_Happy_ACMer
  • A_Happy_ACMer
  • 2015年01月21日 08:38
  • 239

问题七十:Box of Bricks (ACM)

描述 Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds s...
  • liuyongshui4979
  • liuyongshui4979
  • 2013年04月23日 16:45
  • 644

Brick笔记(一)

开篇 今得闲,便想来把前阵研发的Brick框架也写来分享一下,以此记录Brick的成长。 本人工作过程中发觉于公司做了很多项目后,却很少真正沉淀,实忒糟蹋心血;另现今框架层出不穷,琳琅满目,不乏精...
  • issing
  • issing
  • 2014年02月28日 17:22
  • 930

人脸检测中的bounding box regression详解

在人脸检测算法如R-CNN、Fast RCNN中都用到了bounding box回归,回归的目标是使得预测的物体窗口向groundtruth窗口相接近。我一开始没理解如何能回归出一个框来,看完下文就理...
  • elaine_bao
  • elaine_bao
  • 2017年03月05日 17:17
  • 6175

Group Box组合框的简单使用

分类: 2010.9-14.72013-07-13 11:59 5325人阅读 评论(0) 收藏 举报 目录(?)[+] 开发环境版本:Visual Studio ...
  • hanshuning
  • hanshuning
  • 2014年10月31日 17:01
  • 1549

Combo Box控件使用详解

Combo Box (组合框)控件很简单,可以节省空间。从用户角度来看,这个控件是由一个文本输入控件和一个下拉菜单组成的。用户可以从一个预先定义的列表里选择一个选项,同时也可以直接在文本框里面输入文本...
  • xuan_xuan_2
  • xuan_xuan_2
  • 2016年09月08日 11:53
  • 6873

Combo Box(组合框)控件使用总结

本人亲测: 转自:http://blog.sina.com.cn/s/blog_84f7fbbb01013puc.html
  • u014378023
  • u014378023
  • 2014年08月10日 02:03
  • 1150

gluster 安装配置基本指南

基于网络上的多篇文章,做了一些调整。 gluster安装 ###  Installing Gluster wget -P /etc/yum.repos.d http://downlo...
  • xyw591238
  • xyw591238
  • 2016年06月06日 17:26
  • 695

MFC中List box的用法

List Box应该是同时具有Edit Control和Combo Box的一些特性.说它像前者因为它可以把所有的内容分行显示出来(但不可编辑),所以一般起显示信息的作用.而Edit Control主...
  • u011672712
  • u011672712
  • 2016年06月19日 09:03
  • 1280
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Box of Bricks
举报原因:
原因补充:

(最多只允许输入30个字)