1477:Box of Bricks

2.9 Box of Bricks(砖 盒)                                      2.9 Box of Bricks  2.9.1 时空限制        Time limit: 1 Seconds Memory limit: 32768K 2.9.2 题目内容           Little Bob likes playing with his box of bricks. He puts t... 阅读详情
Problem Description
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 consideration, 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≤n≤50 and 1≤hi≤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, print the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line between each set.
 
Sample Input
6
5 2 4 1 7 5
0
 
Sample Output
Set #1
The minimum number of moves is 5.
 

代码如下:

//acm 1477:Box of Bricks
#include <iostream>
using namespace std;

int main()
{
	int n,k = 1; //有 n 摞砖

	while (cin >> n && n)
	{
		int *a = new int[n];
		int sum = 0,all_move_times = 0; //hi 表示每摞砖的高度
		for (int j = 0;j < n;j++)
		{
			cin >> a[j];
			sum += a[j];
		}
		int avr_height = sum / n;
		for (int j = 0;j < n;j++)
		{
			if(a[j] < avr_height)
				all_move_times += (avr_height - a[j]);
		}
		cout << "Set #" << k++ << endl;
		cout << "The minimum number of moves is " << all_move_times << "." << endl << endl;

		delete []a;
	}

	return 0;
}


ESP32-S3开发环境避坑指南:VS Code+ESP-IDF离线安装全流程(附国内镜像加速) 本文提供了一份详细的ESP32-S3开发环境离线安装指南,重点解决网络依赖问题。通过整合国内镜像加速,手把手教你完成VS Code、ESP-IDF框架、工具链及Python依赖的本地化部署,实现稳定、可重复的开发环境搭建,大幅提升IoT开发效率。 阅读详情

相关推荐

整理的15个公开且可直接使用的电力视觉输电线路领域数据集

而巡检数据是目前来说影响我们做科研的最大阻碍,为此本内容主要总结了,现有的且公开免费的巡检数据集,供大家使用。STN PLAD数据集133个航拍图像,五个电力部件:电力塔及其塔的ID、绝缘子,防震锤,联板(yoke),图像的尺寸在5472×3648到5472×3078。IDID数据集:2000张图像,包含三个类别,正常绝缘子,破损绝缘子和闪络绝缘子三个类别,用于目标检测的实验。TTPLA数据集,用于实例分割,1100张尺寸为3840×2160,包含两个类别,电力杆塔和电力线。主要用于电力杆塔的目标检测。

weixin_42048361的博客 5018

HDU 1326 Box of Bricks

Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different hei

可可 の 猫 874

药物重定位实战:如何用反向找靶技术挖掘老药新用(附Python代码示例)

本文详细介绍了药物重定位中的反向找靶技术,通过分子相似性计算、机器学习模型和结构对接等方法,挖掘已有药物的新治疗潜力。附Python代码示例,帮助读者快速实现从分子结构到潜在靶标的智能预测,显著提升药物研发效率。

weixin_28726671的博客 259

Box of Bricks

Problem Description 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 Al...

柠檬超级酸 345

Procedural modeling

What is procedural modeling? One content generation option is modeling buildings, plants, clouds, cities, and worlds using an underlying system of rules. 1 Procedural Modeling: Grammars A rule-based generative system loosely organized as: ...

qq_24505417的博客 711

弘玑RPA进阶攻略

01.弘玑RPA产品概要。02.设计器的安装与卸载。03.设计器特性与使用。

长安诗社社长@-梁瀚文- https://github.com/HevnChin https://gitee.com/HevnChin 3646

1177: 零起点学算法84——Box of Bricks

Description 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

Zichel77的博客 434

网络设备心跳线带宽高导致虚拟化平台不稳定的问题处理

本文记录了网络设备心跳线带宽高导致虚拟化平台不稳定的问题处理一例。

forestqq的博客 2228

【C语言做题系列】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 ...

王保保的小博客 1095

Workbench中直接调用ICEM CFD进行网格划分

自从ANSYS 12.0之后,ICEM CFD就从Workbench中被分离出去,作为一个独立的程序使用了。取而代之的是Meshing模块。 在Meshing的属性节点菜单中右键点击Mesh,选择Insert > Method,插入方法。 选择需要划分网格的几何体,点击apply。此时Geometry显示为1 Body。 设置Method为MultiZone,如果不设置成这个的话,找不到进入ICEM CFD的入口。如果要划分四面体,可以在Mapped Mesh Type中选择其他类型。

Yan的博客 6513

2024年淘宝平板电脑销售数据分析

本项目的目标是从淘宝电商平台上自动化爬取商品信息,并通过数据分析帮助了解价格、销量等相关指标,为商业决策提供支持。使用Selenium实现数据爬取,结合Python的数据处理与可视化工具,进一步分析和展示结果。

2301_76728517的博客 1474

POJ 1477:Box of Bricks

Box of Bricks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19949   Accepted: 8029 Description Little Bob likes playing with his box of bricks. He puts the

小坏蛋_千千 642

CMake入门教程【基础篇】在Windows、Linux上安装CMake

CMake如何下载与安装

小鱼酱的博客 2727

POJ——1477 Box of Bricks

Box of Bricks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19420   Accepted: 7838 Description Little Bob likes playing with his box of bricks. He puts the

逝水流年轻染尘 517

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

PKU 1477 Box of Bricks

Box of BricksTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 9698Accepted: 4233<br />DescriptionLittle Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. "Look, I've bui

luoxiaozheng的专栏 766

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

1477 Box of Bricks

Description 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.

zbc6063054的专栏 1136

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ 1477 Box of Bricks

Description Little Bob likes playing withhis box of bricks. He puts the bricks one upon another and builds stacks ofdifferent height. "Look, I've built a wall!", he tells his oldersister Alice. "Nah,

涅槃phy的专栏 876

poj1477 Box of Bricks 贪心大水题

题目链接:http://poj.org/problem?id=1477 大水题,

basement_boy 585

poj 1477 Box of Bricks

//这题只是让你求给出的数的平均数即可!再通过续一比较,不够平均数的就从多于平均数中补上! #include using namespace std; int num[55]; int main() { int n, i, tc = 0, sum, avg, ans; while (cin >> n) { if (n == 0) break;

yzl_rex 1590

12 POJ1477 Box of Bricks

题目保证有解,先求砖块数的平均数。 再把多的部分移到缺的地方,答案就是多的部分的和。 #include int n,ans,sum,cas=1,avg,i,h[55]; int main() { while(~scanf("%d",&n)&&n) { sum=ans=0; for(i=0;i<n;i++) scanf("%d",&

Unknown 675

poj1477 Box of Bricks

在OJ题目分类的网页上找到这个题

王旻宇 590

poj1477 box of bricks

//这题只是让你求给出的数的平均数即可!再通过续一比较,不够平均数的就从多于平均数中补上! 简单的题目! #include using namespace std; int num[55]; int main() { int n, i, tc = 0, sum, avg, ans; while (cin >> n) { if (n == 0) br

acm_JL的博客 524

[POJ1477]Box of Bricks

Time Limit:1000MS Memory Limit:10000K Total Submissions:19503 Accepted:7871 Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ...

weixin_30491641的博客 98

pku 1477 Box of Bricks

<br />题意:给了你一堆高度不同的木块问你经过几次的移动可以达到木块的高度一样。<br />解法:水题  看懂就可以做的题目。<br />代码:<br />#include<stdio.h><br />int main()<br />{<br />  int a[1000],n,i,average,sum,mnum,count=0;<br /> <br />  while(scanf("%d",&n),n)<br /> {<br />    count++;<br />    sum=0;<br /> 

kyou007的专栏 413
上一篇: 1089-1096:A+B for Input-Output Practice
下一篇: 2317:Nasty Hacks
xiaofei2010
博客等级 码龄17年 172粉丝 120原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值