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 ...
随机推荐
- 删除: warning C4996: 'sprintf': This function or variable may be unsafe. Consider 方法
可以使用的最简单的方法: 选项Project | Configuration Properties | C/C++ | Preprocessor | Preproc ...
- AIDL使用详解
一.对AIDL进行说明 AIDL允许定义一个编程的接口来作为客户端和服务端通信的桥梁,AIDL定义了客户端和服务端的编程标准,在Android里边一个进程无法直接访问另一个进程的内存信息,但是要访问的 ...
- Ext.net中常用的三种交互方式
http://www.ext.net.cn/forum.php?mod=viewthread&tid=10433
- Smarty模板Windows下写代码 放到CentOS6.5无法正确解析
如题:报错: Unable to load template file 'System/header.htm' in '/var/www/website/cms/Template/Default/We ...
- centos安装python gcc sqlite
终端中输入命令:yum install gcc -y yum install python -y yum install sqlite -y
- 基于RAF的一个小动画框
RAF也即是requestAnimationFrame,之前的动画都是基于setTimeout写的,所以为了性能方面的考虑,开始使用requestAnimationFrame写动画. function ...
- Android 程式开发:(二十)内容提供者 —— 20.6 自定义ContentProvider的使用
现在,ContentProvider已经创建好了,可以去尝试使用一下. 1. 使用之前的工程,在布局文件main.xml中添加一些控件. <?xml version="1.0" ...
- asp.net 通过 Handler 导出数据至excel (让用户下载)
效果图: 代码: Export2Excel.ashx <%@ WebHandler Language="C#" CodeBehind="Export2Excel.a ...
- 数学之路-python计算实战(15)-机器视觉-滤波去噪(归一化块滤波)
# -*- coding: utf-8 -*- #code:myhaspl@myhaspl.com #归一化块滤波 import cv2 import numpy as np fn="tes ...
- 怎样安装配置tomcat 8
链接地址:http://jingyan.baidu.com/article/ff42efa91132a0c19e220208.html Apache tomcat 是目前最为流行的java网站开发的服 ...