描述

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?

输入

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.

输出

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.

样例输入

6
5 2 4 1 7 5
0

样例输出

Set #1
The minimum number of moves is 5.
#include<stdio.h>
int main(void)
{
int n, sum, ans, average, count = ;
int a[]; while(scanf("%d", &n) && n)
{
sum = ans = ;
for(int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
average = sum / n;
for(int i = ; i <= n; i++)
{
if(a[i] < average)
ans = ans + average - a[i];
}
printf("Set #%d\nThe minimum number of moves is %d.\n\n", count++, ans);
} return ;
}

OpenJudge_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. 线程安全之suspend(挂起) 和resume(执行)

    suspend()不会释放锁 如果加锁发生在resume()之前会发生死锁 t.join()是阻塞此方法,此线程再继续:通常用于在main()主线程内,等待其它线程完成再结束main()主线程.图中j ...

  2. Java创建对象的原则

    开闭原则 可以通过“抽象约束.封装变化”来实现开闭原则,即通过接口或者抽象类为软件实体定义一个相对稳定的抽象层,而将相同的可变因素封装在相同的具体实现类中 里氏替换原则 里氏替换原则通俗来讲就是:子类 ...

  3. 2019-8-31-dotnet-获取用户设备安装了哪些-.NET-Framework-框架

    title author date CreateTime categories dotnet 获取用户设备安装了哪些 .NET Framework 框架 lindexi 2019-08-31 16:5 ...

  4. LUOGU P1680 奇怪的分组

    题目背景 终于解出了dm同学的难题,dm同学同意帮v神联络.可dm同学有个习惯,就是联络同学的时候喜欢分组联络,而且分组的方式也很特别,要求第i组的的人数必须大于他指定的个数ci.在dm同学联络的时候 ...

  5. bzoj 4241 历史研究——分块(区间加权众数)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4241 套路:可以大力预处理,如果求区间加权众数,可以预处理i~j块(或 j 位置)的最大值, ...

  6. CSS--去除除文本基线的几种方式

    削除文本基线的几种方式:1.display:block2.vertical-align:middle3.font-size:0px

  7. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---门面模式之HomeTheater[转]

      1unit uSubObject;   2   3interface   4   5type   6   7  { TAmplifier与TTuner,TCDPlayer,TDVDPlayer相互 ...

  8. java swing调试时线程显示名字

    一般有一个默认名字 但是具体运行到哪一个线程,需要猜 为了节约时间,提高效率 可以给线程写个中文名(因为默认就是英文,写中文,一眼就能挑出来) 以RTC定时器为例子 final TimerRtc ti ...

  9. NOIP模拟 17.9.28

    公交车[问题描述]市内有

  10. 【洛谷】P1880 石子合并

    P1880 石子合并 题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计 ...