Leetcode 406. Queue Reconstruction by Height

从零开始STM32cubeide学习 使用的是正点原子的精英版,单片机是STM32F103ZET6,详细讲解完成跑马灯实验 阅读详情

Leetcode 406. Queue Reconstruction by Height

source url

题目描述

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this person who have a height greater than or equal to h. Write an algorithm to reconstruct the queue.

输入:
输出:排序后的队伍
如:

Input:
[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]

Output:
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]

思路1.

先对输入的序列对进行排序,首先根据高度排序,高度大的在前面;其次,当高度相同时,k小的在前。上述排序过后结果为:[[7,0],[7,1],[6,1],[5,0],[5,2],[4,4]]。随后,组成序列。基本思路是,大的数字先插入,插入位置为k。这样,能保证在插入第(i,k)时,已有序列本身都>=i,这是插到第k个位置是合理的。这种贪心策略每一步都是合理的。

代码

class Solution {
public:
    static bool comp(pair<int, int>& p1, pair<int, int>& p2){                    
        return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second); 
    }

    vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
        vector<pair<int, int>> res;
        sort(people.begin(), people.end(), this->comp);
        for (int i =0;i<people.size();i++) {
            pair<int, int>& p = people[i];
            res.insert(res.begin() + p.second, p);}
        return res;
    }
};
使用PLINK做GWAS(2) 利用PLINK对单基因控制的性状进行定位,之前一篇文章粗滤的记录了一下使用PLINK的命令,本次博客主要记录一下如何根据SNP芯片的数据制作PLINK的格式,以及分析的步骤,最后数据的可视化。 首先,有的公司给的新片的数据就是一个excel表格,列表示的是样品,行表示的是基因型,基因型用ATCG构成,当然有的基因型是用数字0或者1表示的。下面我拿到的一个数据是15个样品构成的基因型,有13个样品是突变体,2个样品是野生型。 格式如下: 第二步:将此基因型存成csv文件,使用R进行读取,在R中制作pl 阅读详情

相关推荐

Marin说PCB之LPDDR5的布线注意事项--03

这个规则中是把每个字节中的WCK to RDQS 以及DM / DQ to WCK等长规则都加到了DM / DQ这个等长规则中去了,因为芯片手册上的设计要求中的DM / DQ这个group的等长误差是+-50MIL, WCK to RDQS的等长group的规则是62.5MIL,DM / DQ to WCK等长group的规则是相对松一些是150MIL。其实上面的等长规则还是建少了一些的,例如手册上要求的每个channel的WCK0:1,WCK2:3等长误差在+-488MIL,这个规则建议还是补上去吧。

weixin_45223454的博客 1231

LeetCode //C - 406. Queue Reconstruction by Height

【代码】LeetCode //C - 406. Queue Reconstruction by Height。

Made in Code 1006

Xlinx PG151 除法器IP 笔记

对Xlinx 除法器IP PG151中部分内容记录备忘。

weixin_50515160的博客 2528

LeetCode406. Queue Reconstruction by Height

先根据h进行排序,之后根据k进行排序。

叶卡捷琳堡的博客 966

ubuntu18.04安装xenomai3.1(百分百成功版)

ubuntu18.04安装xenomai3.1(百分百成功版),保姆级教学!!!

h542812556sdu的博客 2065

微信取证不求人:最新免费DAT解码工具使用指南(含闪退解决方案)

本文提供了一份详细的微信DAT文件免费解码工具使用指南。针对用户常见的图片无法查看问题,手把手教学如何安全获取并操作开源图形化工具,将加密的DAT文件一键还原为JPG/PNG图片。文章重点剖析了DAT文件的加密原理,并给出了详细的步骤解决工具运行中最常见的“程序闪退”等疑难杂症,帮助普通用户轻松完成微信取证。

m0n1o2p的博客 480

LeetCode 406 Queue Reconstruction by Height

LeetCode 406 Queue Reconstruction by Height 题解 题意 给定一组数列,数列中每个元素为一对数(h, k),其中h表示该元素的值,k表示该元素之前所有元素中,值大于等于当前元素值的个数。这个数列被打乱了,要求重新排列这个数列使其正确。 思路 一 考虑最大元素 对于值为最大值的元素来说(可能多个),倘若将它们按照k从小到大排序,会发现他们的k值其实就是他们的...

EricJeffrey的博客 308

【YOLOv11改进 - 特征融合】SDI:多层次特征融合模块,替换contact操作

【YOLOv11改进 - 特征融合】SDI:多层次特征融合模块,替换contact操作

专注于图像领域,主要研究内容包括计算机视觉和深度学习,特别是在图像分类、目标检测和图像生成等方面有深入的研究和实践经验。 1771

【LeetCode】406. Queue Reconstruction by Height

406. Queue Reconstruction by Height Description: Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the pers...

Freemanzxp 326

10、硬件工程师笔试面试——继电器(2025版本)

在设计电路时,应综合考虑SSR的优势和局限性,确保选择合适的型号,并采取适当的设计措施来优化性能和可靠性。继电器的主要功能是利用较小的电流或电压来控制较大电流或电压的电路,实现信号的放大和隔离。在处理继电器故障时,应综合考虑电源、线圈、触点和负载等因素,及时进行故障诊断和处理,以确保电路系统的稳定性和安全性。由于汽车电子系统的复杂性,继电器的设计和选择必须考虑到系统的特定要求,包括电流容量、电压等级、环境条件(如温度、湿度、振动)以及所需的保护和隔离功能。确定线圈的工作电压或电流,以及吸合电压或电流。

XU157303764的博客 3734

【Unity 实用工具篇】 | Unity网格破碎插件 unity-fracture

前面写过一篇Unity中物体破碎效果的插件:【Unity 实用工具篇】 | Unity物体破碎效果 OpenFracture 本文介绍一个另外的工具unity-fracture,也可以实现网格破碎效果,且功能与OpenFracture略有差异。

努力前行,总会成为自己心中的那道光 1万+

leetcode 406. Queue Reconstruction by Height

leetcode 406. Queue Reconstruction by HeightProblemSolutionGreedy Problem Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h i...

weixin_45764148的博客 182

【项目实战】YOLOV5 +实时吸烟目标检测+手把手教学+开源全部

本原创项目长期更新,旨在完成校园异常行为实时精检测,做到集成+N次开发+优化(不止局限于调包)为止,近期将不断更新以下模型+数据+标注文件+教程。关注博主,Star 一下github,一起开始美妙的目标检测之路吧~~ 文章目录本原创项目长期更新,旨在完成校园异常行为实时精检测,做到集成+N次开发+优化(不止局限于调包)为止,近期将不断更新以下模型+数据+标注文件+教程。关注博主,Star 一下github,一起开始美妙的目标检测之路吧~~一、项目展示二、项目资源共享1:训练图片:香烟图片+吸烟手势+烟雾三、

cv君的博客 13万+

LeetCode 406. Queue Reconstruction by Height【Java】

题目描述 406. 根据身高重建队列 AC代码 按照身高从大到小排序。 身高相同,按照kkk从小到大的顺序排序。 class Solution { public int[][] reconstructQueue(int[][] people) { //按照身高和k进行排序 Arrays.sort(people,new Comparator<int[...

NayelyA的博客 250

老版QQ原生表情gif动态

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

LeetCode-406. Queue Reconstruction by Height [C++][Java]

You are given an array of people,people, which are the attributes of some people in a queue (not necessarily in order). Eachpeople[i] = [hi, ki]represents theithperson of heighthiwithexactlykiother people in front who have a height greater than o

贫道绝缘子的博客 554

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

[LeetCode]406. Queue Reconstruction by Height

[LeetCode]406. Queue Reconstruction by Height题目描述思路参考了答案解法 people: [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]] 排序后: [[7,0], [7,1], [6,1], [5,0], [5,2], [4,4]] 然后从数组people第一个元素开始,放入到数组result中,放入

Lcharon的博客 471

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LeetCode 406. Queue Reconstruction by Height 解题报告

LeetCode 406. Queue Reconstruction by Height 解题报告

骆小坑的填坑之旅 5429

LeetCode406. Queue Reconstruction by Height题解

最近算法课讲到了贪心算法,接下来的几篇题解应该都会与贪心算法相关。1. 题目描述Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k

SYSU_LBY的博客 394

leetcode406 Queue Reconstruction By Height java

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of t

店小不二的博客 595

LeetCode406 Queue Reconstruction by Height

now we are given a queue that consist of tuples, say (h, k), h stands for the height of this person and k stands for the number of person taller or equals to him who stand ahead of him. we are given a disordered queue, and we need to restore the order as i

Tech in Pieces 308

LeetCode406:Queue Reconstruction by Height

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of this ...

卷卷萌的博客 216

LeetCode:406. Queue Reconstruction by Height

LeetCode:406. Queue Reconstruction by Height Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person an...

Wisimer 205

[leetcode] 406. Queue Reconstruction by Height 解题报告

题目链接:https://leetcode.com/problems/queue-reconstruction-by-height/ Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), where h is

小榕流光的专栏 6014

【LeetCode 406】Queue Reconstruction by Height

题意: Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of t...

iCode_girl的博客 125

[LeetCode 406] Queue Reconstruction by Height

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of this ...

ExcitedZhang的博客 130

LeetCode OJ 406. Queue Reconstruction by Height

LeetCode OJ 406. Queue Reconstruction by HeightDescriptionSuppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of t

jan_deng的博客 289
上一篇: Leetcode 513. Find Bottom Left Tree Value
下一篇: Leetcode 455. Assign Cookies
vincentCheungM
博客等级 码龄10年 4粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值