591 - Box of Bricks
| Box of Bricks |
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and buildsstacks of different height. ``Look, I've built a wall!'', he tells his older sister Alice. ``Nah, you shouldmake 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 allstacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimumnumber 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 stacksBob has built. The next line contains
n numbers, the heights
h
i of the
n stacks. You may assume
and
.
The total number of bricks will be divisible by the number of stacks. Thus, it is always possibleto 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 thathave 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(void)
{
int n,i,count=1;
while(scanf("%d",&n)&&n)
{
int h,k=0,sum=0,a[100]={0};
for(i=0;i<n;i++)
{scanf("%d",&a[i]);sum+=a[i];}
h=sum/n;
for(i=0;i<n;i++)
if(a[i]>h)
k+=a[i]-h;
printf("Set #%d\nThe minimum number of moves is %d.\n\n",count++,k);
}
return 0;
}
591 - Box of Bricks的更多相关文章
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Box of Bricks最小移动砖块数目
Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...
- [POJ1477]Box of Bricks
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19503 Accepted: 7871 Description Litt ...
- HDOJ(HDU) 2088 Box of Bricks(平均值)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- HDOJ 1326 Box of Bricks(简单题)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- Box of Bricks
Box of Bricks Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU 2088 Box of Bricks
http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...
- HDU 2088 Box of Bricks(脑洞)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...
- zoj 1251 Box of Bricks
Box of Bricks Time Limit: 2 Seconds Memory Limit: 65536 KB Little Bob likes playing with his bo ...
随机推荐
- vector的成员函数解析
vector是线性容器,它的元素严格的依照线性序列排序,和动态数组非常相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅能够使用迭代器(iterator)訪问元素,还能够使用指针 ...
- linux 单网卡绑定两个ip
一.ubuntu系统: #vi /etc/network/interfaces OR $ sudo vi /etc/network/interfaces Modify as follows: au ...
- C++赋值运算符与赋值表达式
赋值运算符 赋值符号“=”就是赋值运算符,它的作用是将一个数据赋给一个变量.如“a=3”的作用是执行一次赋值操作(或称赋值运算).把常量3赋给变量a.也可以将一个表达式的值赋给一个变量. 赋值过程中的 ...
- db link 连接不上
两边的数据库,不在一个地方.都是oracle. 试了很多次,有时提示连接拒绝,有时连接不上.后来改了dblink的创建脚本,如下,才成功了. -- Create database link creat ...
- Netty In Action中文版 - 第五章:Buffers(缓冲)
本章介绍 ByteBuf ByteBufHolder ByteBufAllocator 使用这些接口分配缓冲和运行操作 每当你须要数据传输时,它必须包括一个缓冲区.Java NIO API自带的缓冲区 ...
- NVelocity 实例
using System; using System.IO; using System.Collections; using System.Collections.Generic; using Sys ...
- @produces在spring mvc中是什么意思
@RequestMapping(value = "/produces", produces = "application/json"):表示将功能处理方法将生产 ...
- Java ArrayList add(int index, E element) example
Simple add() method is used for adding an element at the end of the list however there is another va ...
- ASP.NET - 匹配标签中的内容
string str = @"<td>Csdn</td>\r\n<td>V1.0</td>\r\n<td>2014-10-23&l ...
- EasyUI - Panel 面板控件
效果: html代码: <div id="p" style="padding: 10px;"> <p>panel content.< ...