Box of Bricks ——平均数问题

【FnOS飞牛云 | NAS存储】旧电脑不吃灰,手把手教你搭建完全属于自己的私人网盘 打造属于自己的NAS私人网盘,亲测有效,值得一试 阅读详情

  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  h i  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 

6
5 2 4 1 7 5
0

Sample Output 

Set #1
The minimum number of moves is 5.



题意很简单,将不等高的数列通过移动砖快改变成等高的,求移动砖块的最少数目。

这道题目的关键就在于想到无论怎么变换,最后的高度都是总的高度除以N,所以只需要求平均数计算出平均高度,然后将超出平均高度的砖移向低于平均高度的地方就可以了。

这样,问题就转换成了求高于平均高度的砖的数目。

不过需要注意的是,每一组数据结束之后有一个空行!!!

#include <stdio.h>
#include <string.h>

int main()
{
    int sum,cha,wall[60],adv;
    int n,i = 1,j;
    while(scanf("%d",&n),n)
    {
        sum = 0;
        for(j = 0;j < n;j++)
        {
            scanf("%d",&wall[j]);
            sum += wall[j];
        }
        adv = sum / n;
        cha = 0;
        for(j = 0;j < n;j++)
        {
            if(wall[j] > adv)
                cha += wall[j] - adv;
        }
        printf("Set #%d\n",i);
        printf("The minimum number of moves is %d.\n\n",cha);
        i++;
    }
    return 0;
}


从入门到精通:Cursor使用全攻略 Cursor是一款基于VSCode深度定制的AI编程工具,由Anysphere公司开发。它将AI技术与代码开发深度融合,能够理解自然语言指令并生成高质量代码,支持代码补全、跨文件上下文理解等功能。本文详细介绍了Cursor的安装设置、界面导航、基本操作和Composer模式等核心功能,并提供了高效提示词写作技巧和实际应用案例(如浏览器插件开发、复杂表单组件构建等)。文章还总结了使用注意事项和常见问题解决方案,展望了AI编程工具的发展前景。Cursor通过智能代码生成和项目理解能力,显著提升了开发效率,适合各 阅读详情

相关推荐

机器学习入门基础 | 基于python的高光谱图像特征挖掘:PCA + 形态学属性处理可视化实战

本文介绍了一种基于PCA和形态学操作的高光谱图像特征提取方法。通过主成分分析降低数据维度,再运用面积开闭操作增强空间结构特征,有效去除噪声并填补孔洞。实验采用WHU-HI-HanChuan数据集,提供完整的Python实现代码,包括数据加载、PCA降维、形态学处理及结果可视化等步骤。该方法能够显著改善图像质量,为后续分类和变化检测任务提供更好的特征输入。实验结果表明,不同阈值的形态学处理能呈现不同程度的空间结构增强效果,对区域生长、分割和聚类等应用具有重要价值。

lestatlu的博客 1046

【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

QT使用高精度定时器

精度相对第二种方法高许多。

ljjjjjjjjjjj的博客 4097

*寒假水64——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 sh...

chengchencheng的博客 277

薛定谔虚拟筛选实战:如何用PDB文件快速构建受体格点(避坑指南)

本文提供了薛定谔虚拟筛选实战指南,聚焦于如何从PDB文件快速、精准地构建受体格点。文章详细解析了可变残基的理性处理策略、基于配体尺寸的盒子量化设置方法,并分享了高级约束与排除体积的实战技巧,旨在帮助用户避开常见陷阱,提升虚拟筛选的成功率与效率。

weixin_28419039的博客 254

RK3568 开发实战:手动构建 Linux 4.19 内核镜像与设备树优化

本文详细介绍了为RK3568开发板手动编译Linux 4.19内核的完整实战流程。从环境搭建、源码获取、内核配置,到设备树深度定制与优化,再到镜像打包与烧写,旨在帮助开发者脱离官方SDK依赖,实现对嵌入式Linux系统的完全掌控,提升硬件适配与性能优化能力。

weixin_29175469的博客 269

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

[LaTeX] 调整参考文献的格式(References),包括作者名缩写,行距,字体,引用顺序等等

在此记录我对LaTeX中参考文献references的尝试,主要涵盖如题几个方面。

the Blog of 等不到天亮丶等时光 4万+

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

追随梦想,实现梦想 920

3、数据导入与清洗:Excel、SQL、SPSS、Stata和SAS数据处理

本文详细介绍了如何从Excel文件、SQL数据库以及SPSS、Stata和SAS等统计软件中导入和清洗数据。针对不同数据来源的特点,提供了具体的处理方法,包括跳过无用行、重命名列、处理缺失值、转换数据类型、保留元数据等关键步骤。同时,通过实际应用案例展示了如何整合多源数据,并总结了数据导入和清洗的最佳实践,帮助读者高效完成数据预处理工作,为后续的数据分析打下坚实基础。

134

使用 MATLAB/Simulink + Simscape Electrical + Simulink Design Optimization,构建一个沙漠环境中光伏组件灰尘积累与效率下降仿真模型

本文通过,构建了沙漠环境中光伏组件灰尘积累与效率下降仿真模型✅ 建立了风速-沙尘-积尘速率的物理关系✅ 仿真了灰尘积累过程及其对Isc 和 Pmax的影响✅ 量化分析了不同清洁策略的经济性✅ 提出了优化设计与智能运维建议。

xiaoheshang_123的博客 123

1.29 [hduoj] 2088 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 A...

棉毛裤穿吗 373

把云端打印带回办公室:通信场景 SAP_COM_0466 打通 SAP BTP ABAP environment 与本地打印机的 Pull Integration 实战

摘要: 本文探讨云端SAP系统如何通过SAP_COM_0466通信场景实现与本地打印机的安全连接。核心方案采用Pull Integration模式,由本地组件(如SAP Cloud Print Manager或第三方OMS)主动从云端打印队列拉取任务,避免网络边界冲突。配置流程涵盖通信安排创建、打印队列绑定及权限管理,并强调队列类型必须选择"Pull Integration Queue"的关键细节。方案通过分离云端生产与本地打印环节,既保障安全性又便于运维监控,适用于SAP BTP AB

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 144

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

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

hdu 1326 Box of Bricks

此题不是太复杂,通过题目中的 But since Bob is lazy he wants to do this with the minimum number of bricks moved. 这一句话可知要求的移动的的砖块最少既是让我们尽可能少的移动砖块。 首先是通过while循环以保证在输入0之前程序可以一直不停的执行。而while循环中的n则是表示这一堵墙共有多少列,在while循环中在通过for循环输入n个数,存入数组a[i],这n个数则表示初始时这一堵墙每一列的砖的数目。然后通过:砖的总数/列.

qq_45693271的博客 216

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

UVA - 591 Box of Bricks

2016-07-22 UVA - 591 Box of Bricks 题目大意:移动方块使所有列一样高,一次一个,求移动次数。 解题思路:求平均数然后计算每列大于平均数的个数。 #include #include using namespace std; int main() { int N = 0; int n; while ( scanf("%d",&n

振丿Love 326

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

uva 591 Box of Bricks

平均数简单题目 #include #define MAX_LEN 51 int h[MAX_LEN]; int case_count; void func(int n) { int i; int sum, aver; sum = 0; for(i=0; i<n; i++) sum += h[i]; aver = sum/n; sum = 0; for(i=0;

皓首不倦 不负少年 683

Uva 591 - Box of Bricks

<br />没什么说的,不过因为想尝试一下C++,由于scanf导致 了两次CE,唉~~~<br />#include<iostream> #include<list> using namespace std; int main(void) { int n,set = 0; while(cin>>n && n != 0) { list<int> vec; int sum =0,count = 0; set++; int t; for(int i = 0

My Own Space 645

Uva 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 si

小G的ACM之路 930

UVa 591 - Box of Bricks

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 s

ACM2272902662的专栏 1111

ZOJ Problem Set - 1251 Box of Bricks

Box of Bricks Time Limit: 2 Seconds      Memory Limit: 65536 KB Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. ``Look

acm_1361677193的专栏 377

HOJ 1599 Box of Bricks

http://acm.hit.edu.cn/hoj/problem/view?id=1599 计算移动砖块的次数 高度大于平均数的减去平均数求和即可 注意格式 #include int main() { int n, h[128], i, j, sum, avg, count, k; count = 0; while (scanf("%d", &n)

epk_lee的专栏 412

poj 1477 Box of Bricks

很简单的题目,我看完题到AC大概一共就7、8分钟。。。同样比赛的时候希望遇到 不过不太完美的是,我presentation error了一次,原因就是结尾还应该打一个空行。。。如果我继续这么不仔细,真的会吃大亏!吸取教训吧。。。 一道很简单的数学问题,思路是:先求平均数,然后求出每个数与平均数的差(绝对值)并累加,最后输出累加和的一半即可 AC的代码: #include i

This is bill的专属博客 1568

zju1251砖盒Box of Bricks

    最近太挫了,老是不注意格式。 用时:0ms #include #define MAX 110 //ok~ int main() {     freopen("1251.txt","r",stdin);     freopen("output.txt","w",stdout);     int n,num[MAX],i,sum,count,flag=0;     while(scanf("%d",&n)==1)     {       fl

我的计算机学习工作日志 436

UVa 591 - Box of Bricks

水题. 只要算出平均数, 再算出

一只冰熊 1026
上一篇: 1月20号总结
下一篇: The Snail ——蜗牛逃出井
A_Happy_ACMer
博客等级 码龄12年 2粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值