当前位置:网站首页>【华为机试真题详解】高矮个子排队
【华为机试真题详解】高矮个子排队
2022-07-07 08:00:00 【不太灵光的程序员】
前言
《华为机试真题详解 Python实现》专栏含牛客网华为专栏、华为面经试题、华为OD机试真题。
如果您在准备华为的面试,期间有想了解的可以私信我,我会尽可能帮您解答,也可以给您一些建议!
本文解法非最优解(即非性能最优)。
题目描述
现在有一队小朋友,他们高矮不同,我们以正整数数组表示这一队小朋友的身高,如数组{5,3,1,2,3}。
我们现在希望小朋友排队,以“高”“矮”“高”“矮”顺序排列,每一个“高”位置的小朋友要比相邻的位置高或者相等;每一个“矮”位置的小朋友要比相邻的位置矮或者相等;
要求小朋友们移动的距离和最小,第一个从“高”位开始排,输出最小移动距离即可。
例如,在示范小队{5,3,1,2,3}中,{5, 1, 3, 2, 3}是排序结果。{5, 2, 3, 1, 3} 虽然也满足“高”“矮”“高”“矮”顺序排列,但小朋友们的移动距离大,所以不是最优结果。
移动距离的定义如下所示:
第二位小朋友移到第三位小朋友后面
边栏推荐
- Differences between MCU and MPU
- 学习记录——高精度加法和乘法
- Before joining the chain home, I made a competitive product analysis for myself
- ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
- Enterprise practice | construction of banking operation and maintenance index system under complex business relations
- Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
- Internship log - day07
- Win10安装VS2015
- ES类和对象、原型
- ES6中的原型对象
猜你喜欢
Bean operation domain and life cycle
The landing practice of ByteDance kitex in SEMA e-commerce scene
【二开】【JeecgBoot】修改分页参数
ORM--数据库增删改查操作逻辑
SQLyog数据库怎么取消自动保存更改
Guide de signature du Code Appx
The physical meaning of imaginary number J
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Leetcode exercise - 113 Path sum II
Some thoughts on the testing work in the process of R & D
随机推荐
Introduction to uboot
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
Integer inversion
喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
能源路由器入门必读:面向能源互联网的架构和功能
Postman interface test II
ES6中的函數進階學習
. Net configuration system
Postman interface test III
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
web3.0系列之分布式存储IPFS
fiddler-AutoResponder
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Postman interface test V
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Guide de signature du Code Appx
中国首款电音音频类“山野电音”数藏发售来了!
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
arcgis操作:dwg数据转为shp数据