当前位置:网站首页>【华为机试真题详解】高矮个子排队
【华为机试真题详解】高矮个子排队
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} 虽然也满足“高”“矮”“高”“矮”顺序排列,但小朋友们的移动距离大,所以不是最优结果。
移动距离的定义如下所示:
第二位小朋友移到第三位小朋友后面
边栏推荐
- ES6中的函數進階學習
- Word自动生成目录的方法
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- Three years after graduation
- Deadlock caused by non clustered index in SQL Server
- 【acwing】789. 数的范围(二分基础)
- 单片机(MCU)最强科普(万字总结,值得收藏)
- 嵌入式背景知识-芯片
- Before joining the chain home, I made a competitive product analysis for myself
- phpcms实现PC网站接入微信Native支付
猜你喜欢
Internship log - day07
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
The request object parses the request body and request header parameters
Win10 installation vs2015
Google Colab装载Google Drive(Google Colab中使用Google Drive)
Postman interface test VII
Postman interface test V
Some thoughts on the testing work in the process of R & D
ORM--查询类型,关联查询
嵌入式背景知识-芯片
随机推荐
Or in SQL, what scenarios will lead to full table scanning
Memory ==c language 1
ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
C#记录日志方法
ArcGIS operation: batch modify attribute table
Performance optimization record of the company's product "yunzhujia"
The Himalaya web version will pop up after each pause. It is recommended to download the client solution
The combination of over clause and aggregate function in SQL Server
高数_第1章空间解析几何与向量代数_向量的数量积
Three years after graduation
搭建物联网硬件通信技术几种方案
LeetCode 练习——113. 路径总和 II
arcgis操作:dwg数据转为shp数据
How to cancel automatic saving of changes in sqlyog database
【ORM框架】
ORM模型--关联字段,抽象模型类
The request object parses the request body and request header parameters
Internship log - day07
中国首款电音音频类“山野电音”数藏发售来了!
Why are social portals rarely provided in real estate o2o applications?