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 ...
随机推荐
-
python基础:算法是什么
"算法"是什么? 简单来说,算法就是告诉计算机要做什么,是对如何做一件事情的详细描述或者详细的操作步骤. 待补充~~~
-
JSP直接连接sql2008数据库并显示
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage=&qu ...
-
线上问题 - MySQL SQL state [HY000]; error code [1366]
一.问题描述 另外一个系统调用服务接口api:/xxx/create?aName=&time=&...,数据没有保存成功提示SQL state [HY000]; error code ...
-
centos7 nginx安装/启动/进程状态/杀掉进程
1.安装 下载RPM:wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm ...
-
Iptables防火墙规则使用梳理
iptables是组成Linux平台下的包过滤防火墙,与大多数的Linux软件一样,这个包过滤防火墙是免费的,它可以代替昂贵的商业防火墙解决方案,完成封包过滤.封包重定向和网络地址转换(NAT)等功能 ...
-
python SMTP other
HTML 正文,带链接和图片 //test.py import smtplib from email.mime.image import MIMEImage from email.mime.text ...
-
6-3-3ios自动化-数据驱动
https://testerhome.com/topics/14247 #!/usr/bin/env python3 # coding:utf-8 from appium import webdriv ...
-
stm32的VCC/VDD/VSS/VEE/VBAT的区别
先看一下stm32vet6的引脚图吧 电路设计以及PCB制作中,经常碰见电源符号:VCC. VDD.VEE.VSS,他们具有什么样的关系那? 一.解释 VCC:C=circuit 表示电路的意思, 即 ...
-
北京Uber优步司机奖励政策(4月18日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
-
python 利用 setup.py 手动安装第三方类库
python 利用 setup.py 手动安装第三方类库 由于我在mac使用时,装了python3,默认有python2的环境,使用 pip 安装第三方类库时,老是安装到 python2的环境上: 在 ...