博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[解题报告]591 - Box of Bricks
阅读量:6720 次
发布时间:2019-06-25

本文共 1737 字,大约阅读时间需要 5 分钟。

  Box of Bricks 

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?

 

 

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 Ÿ\le n \leŸ 50$ and$1 \leŸ h_i Ÿ\le 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 

65 2 4 1 7 50

 

Sample Output 

Set #1The minimum number of moves is 5.

 

 


Miguel A. Revilla 
1998-03-10
 
 
 
 
 

最小移动次数的计算方法:

1、算出平均数,即移动完毕后,每组有几个盒子
2、算出平均数减每组的绝对值
3,将算出的绝对值相加除2就是最小移动次数

 
 
 
#include
int main(){ int setnum=1,i; int n,box[55],average,count; while(scanf("%d",&n)!=EOF&&n) { average=0; count=0; for(i=0;i

 

转载于:https://www.cnblogs.com/TheLaughingMan/archive/2013/02/21/2919884.html

你可能感兴趣的文章
小成本对付宽带我世界实现有线/无线同时上网
查看>>
QT TableWidget应用笔记
查看>>
yum安装Apache Web Server后各个文件存放位置
查看>>
定制更友好的iptables防火墙
查看>>
做软件产品,一定要及时响应用户反馈,及时更新
查看>>
Exchange Server2013 系列:证书的配置
查看>>
以太网帧识别VLAN
查看>>
CloudStack+XenServer详细部署方案(1):方案规划设计
查看>>
php 防止爬虫设置
查看>>
完全卸载MySQL服务
查看>>
人生生活必经历的现实,建议大家经常看看
查看>>
我的友情链接
查看>>
【部分补充】【翻译转载】【官方教程】Asp.Net MVC4入门指南(4):添加一个模型...
查看>>
C# 简介
查看>>
java 两个数交换问题
查看>>
css核心
查看>>
redhat6.0安装步骤
查看>>
央视广告招标京东成黑马 茅台是标王
查看>>
CnetOS 6.6 rsync 的服务端和客户端配置
查看>>
mysql双主同步配置
查看>>