Box of Bricks

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 63   Accepted Submission(s) : 20
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 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? [center][img]../../data/images/1326-1.gif[/img][/center]
 
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
6 5 2 4 1 7 5 0
 
Sample Output
Set #1 The minimum number of moves is 5.
 
Source
Southwestern Europe 1997

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

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. 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. CodeForces 696C PLEASE

    快速幂,费马小定理,逆元. 设$dp[n]$表示$n$次操作之后的概率,那么$dp[n] = \frac{{(1 - dp[n - 1])}}{2}$.$1-dp[n - 1]$表示上一次没有在中间的 ...

  2. [妙味DOM]第六课:鼠标滚轮和COOKIE

    知识点总结: 鼠标滚轮事件 存在兼容性问题: IE/chorme : onmousewheel FF : DOMMouseScroll,必需用在addEventListener下,例如: if (ob ...

  3. JUnit test case 执行顺序

    转自:JUnit中按照顺序执行测试方式 很多情况下,写了一堆的test case,希望某一些test case必须在某个test case之后执行.比如,测试某一个Dao代码,希望添加的case在最前 ...

  4. 关于Android L软件安装问题的发现

    android5.0可能存在的问题: 保留数据刷入导致通知栏无法下拉 按home键不能回到桌面 sdcard无法读取等等 刷了Android L之后,有一部分软件无法正常安装,多表现为 同一家公司开发 ...

  5. 2.Math对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. jQuery实例2

    下拉框实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  7. Java中的Unsafe

    在阅读AtomicInteger的源码时,看到了这个类:sum.msic.Unsafe,之前从没见过.所以花了点时间google了一下. Unsafe的源码:http://www.docjar.com ...

  8. HDU 2064 汉诺塔III(递归)

    题目链接 Problem Description 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘 ...

  9. MVC3+EF4.1学习系列(九)-----EF4.1其他的一些技巧的使用

    上节通过一系列重构 简单的项目就实现了 不过还有些EF的功能没有讲 这节就通过项目 讲讲EF其他的功能与技巧 一.直接执行SQL语句 通常来讲 EF 不用写SQL语句的  但是 在有些场合  比如对生 ...

  10. 取URL得值

    有这样一个URL:http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e,请写一段JS程序提取URL中的各个GET参数(参 ...