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. Nginx+Apache实现反向代理

    一 反向代理 1.1 反向代理是什么 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器, 并将从服务器上得到的结果返回给 ...

  2. C#_FindWindow

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. ListView的条目点击焦点的问题

    由于ListView条目里有ImageButton,导致抢占了条目点击事件,所以在item的跟布局中加入 android:descendantFocusability="blocksDesc ...

  4. 《Mastering Opencv ...读书笔记系列》车牌识别(I)

    http://blog.csdn.net/jinshengtao/article/details/17883075/  <Mastering Opencv ...读书笔记系列>车牌识别(I ...

  5. YII学习第二十三天,accessRules用法

    访问控制过滤器(Access Control Filter)访问控制过滤器是检查当前用户是否能执行访问的controller action的初步授权模式. 这种授权模式基于用户名,客户IP地址和访问类 ...

  6. Highest Rated Features

  7. 与malloc有关的问题

    nefu 1026 申请动态空间存放字符串,将其排序后输出 http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1026 #in ...

  8. Just do it!!!

    从今日起,开个开发自己个人轻量级博客,加油!!!!!

  9. java代码块 静态、非静态

    Java虚拟机的内存分区:Java栈.堆.方法区.本地方法栈.PC寄存器.还有一个常量池的概念,虚拟机会为每种类型分配一个常量池,而不是实例. 例如有一个类有很多子类,那么在父类定义的final变量, ...

  10. SharePoint2013 Excel导出好的代码

    C#Excel操作类ExcelHelper.cs 来源:http://www.hellocsharp.com/article/67.aspx C#源码世界 发布于: 2014-09-12 使用本类之前 ...