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 ...
随机推荐
- iOS开发中关于本地数据中SQLite数据库常用的SQL语句
创建表 CREATE TABLE IF NOT EXISTS "student" ("number" INTEGER PRIMARY KEY AUTOINCRE ...
- c++实现查询天气预报
原地址:http://blog.csdn.net/x_iya/article/details/8583015 用到的函数.API等 1.中央气象台API返回的JSON数据(http://m.weath ...
- [转]PostgreSQL 中文资料汇总
原文链接:http://francs3.blog.163.com/blog/static/405767272014017341219/ --1 中文社区网站 PostgreSQL 中文社区官网: h ...
- db link 连接不上
两边的数据库,不在一个地方.都是oracle. 试了很多次,有时提示连接拒绝,有时连接不上.后来改了dblink的创建脚本,如下,才成功了. -- Create database link creat ...
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序 在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity ...
- hdu 1166 敌兵布阵(线段树,树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1166 直接线段树模板 AC代码: #include<iostream> #include<cs ...
- SQL Server 存储过程、触发器、游标
存储过程 1.存储过程是事先编好的.存储在数据库中的程序,这些程序用来完成对数据库的指定操作. 2.系统存储过程: SQL Server本身提供了一些存储过程,用于管理有关数据库和用户的信息. 用户存 ...
- C# - 委托_求定积分通用方法
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- 编译kernel:配置
韦东山Linux视频第1期_裸板_UBoot_文件系统_驱动初步\第10课第2节 内核启动流程分析之配置.WMV 下面以DM9000的配置为例: 在一个编译好的内核代码里,寻找CONFIG_DM900 ...
- android设置eclipse中的自动提示功能
菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾 (并 ...