UVA 591 - 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... 阅读详情

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 containsn 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 isk.'', 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.



Miguel A. Revilla 
1998-03-10

====================================

问需要的最少的移动步数,求出平均值,多出平均值的部分加在一起就好了


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n,a[55],t=1;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        printf("Set #%d\n",t++);
        int sum=0,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        int ave=sum/n;
        for(int i=0;i<n;i++)
        {
            if(a[i]>ave)
            {
                ans+=(a[i]-ave);
            }
        }
        printf("The minimum number of moves is %d.\n\n",ans);
    }
    return 0;
}

从零搭建:基于Matlab/Simulink与FlightGear的飞行器实时可视化仿真平台 本文详细介绍了如何从零搭建基于Matlab/Simulink与FlightGear的飞行器实时可视化仿真平台。通过环境准备、模型部署、接口配置及联合仿真等步骤,帮助用户快速掌握飞行器仿真的核心技术,实现高效的三维可视化与实时数据交互。 阅读详情

相关推荐

esxi8.0.3如何添加USB外置硬盘

本文介绍了在ESXi系统中配置外置USB硬盘作为数据存储的完整步骤:1)通过SSH禁用USB仲裁服务并关闭自启;2)识别已连接的USB硬盘设备路径;3)使用partedUtil创建GPT分区表并计算扇区范围;4)设置VMFS6分区并格式化。关键命令包括停止usbarbitrator服务、partedUtil分区操作以及vmkfstools格式化命令。整个过程需通过SSH执行,最终将USB硬盘配置为名为"USB_Datastore"的VMFS6存储设备。

qq_41683719的博客 1546

【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

【Codesys】获取从站信息,判断是否从站断联,总线丢失

获取EtherCAT从站信息,判断是否从站断联,总线丢失

qq_35316470的博客 5731

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

放弃FFT全频计算!在STM32F407上用DFT单点计算提速50%的优化技巧

本文详细介绍了在STM32F407上通过DFT单点计算实现比FFT快50%的优化技巧,特别适用于生物阻抗分析、振动监测等只需关注单一频点的嵌入式场景。通过预计算相位角、查表法和混合精度计算等策略,显著提升计算效率和内存利用率,同时保持高精度。

weixin_28738397的博客 194

告别二极管发热!手把手教你用MOS管搭建同步整流电路(附死区时间设置避坑指南)

本文详细介绍了如何利用MOS管搭建同步整流电路(SR),以替代传统二极管,显著降低导通损耗和发热问题。内容涵盖自驱动方案的选择、关键元件参数计算、PCB布局要点及死区时间设置技巧,帮助工程师优化电源设计效率。

weixin_29540599的博客 452

*寒假水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

解决VM 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VM 的方法

在启用了Credential Guard或Device Guard的Windows 10主机上启动12.5版之前的VMware Workstation中的虚拟机时,将显示蓝色诊断屏幕(BSOD)。 会看到类似于以下内容的错误: VMware Workstation和Device / Credential Guard不兼容。禁用Device / Credential Guard后,可以运行VMwar...

Hern(宋兆恒) 39万+

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

【LOGO动态替换】记录一次关于LOGO动态替换引发的uboot代码分析及其实现

文章目录1.前言2.实现2.1 新增logo分区2.2 制作logo分区镜像2.2.1 查看logo.bmp和logo_kernel.bmp的文件大小。2.2.2 按规则将bmp写入logo.img3.分析3.1 uboot的启动分析3.2 uboot bmp load 显示部分3.2.1 rockchip_show_logo3.2.2 load_bmp_logo3.2.3 load_bmp_logo3.3 uboot bmp read部分3.3.1 read_logo_bmps3.3.1 read_bmp

wang 恒 的博客 1213

基于深度学习的文字识别与检测算法研究

基于深度学习的文字识别与检测算法研究 1. 背景介绍 1.1 文字识别与检测的重要性 在当今信息时代,文字作为人类交流和传递信息的主要载体,无处不在。从日常生活中的路牌、广告牌,到办公场所的文件、合同,再到互联网上的网页、图片等

AI天才研究院 1043

UVA 591 (暑假-数学 -D - 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

Bingo 1642

DeepSeek 赋能太空探索:从轨道优化到星际开拓的 AI 革命

随着人工智能技术蓬勃发展,DeepSeek 在太空探索领域展现出巨大应用潜力。本文深入剖析 DeepSeek 技术核心,包括低功耗运算、开源生态等优势,阐述其与传统航天技术的差异。从航天器自主控制、深空探测、载人航天等关键环节,结合实时轨道调整、故障诊断修复等实例,揭示 DeepSeek 对航天任务效率与安全性的提升作用。同时探讨其应用面临的太空环境适应、伦理安全等挑战,展望技术演进方向及与前沿技术融合前景,展现 DeepSeek 为人类太空探索带来的变革与深远意义。

邓邓子的博客 2258

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

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

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 old

不慌不忙、不急不躁 2708

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

UVA591 - 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!'

330

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

UVA 591 - Box of Bricks

这道题的大意是讲:给出一系列的不同高度箱子,要把各各箱子的高度变成相同的高度,问你要移动多少次箱子。很简单,不过得注意输出格式。   #include //#include #include #include using namespace std; int main() {     int n,a[1000],sum,i,temp,count,k = 1;     whil

LAI147的专栏 790

UVa 591 Box of Bricks (模拟)

591 - Box of Bricks Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=532 Little Bob likes playing with his b

AC,∑ndless 1593

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 old

Remilia's 1049

UVA - 591 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 sho

七夜 631

uva 591 Box of Bricks

#include #include using namespace std; int a[60],n; int main() { int num=1; while(cin>>n&&n) { int sum=0; for(int i=0; i<n; i++) { cin>>a[i];

u010652938的专栏 560

UVa 591 - Box of Bricks

#include #include #include #include #include using namespace std; const int MAXN = 52; int A[MAXN]; int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n;

cugfjp的专栏 331

UVa591 - Box of Bricks

题目地址:点击打开链接 注意最后要输出一个空行 C++代码: #include #include using namespace std; int main() { int n; int cas=1; while(true) { cin>>n; if(n==0) break; int sum=0; int average=0; int i; int

220

UVa OJ 题解索引

寂静山林 753

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

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
上一篇: UVA 10025 - The ? 1 ? 2 ? ... ? n = k problem(数学)
下一篇: UVA 573 - The Snail(数学)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值