[LeetCode]406. Queue Reconstruction by Height

用PyTorch实战清华SSVEP数据集:手把手教你搭建第一个脑机接口分类模型(附完整代码) 本文详细介绍了如何使用PyTorch实战清华大学SSVEP数据集,从数据预处理到CNN模型构建的全流程。通过手把手教学,帮助读者搭建第一个脑机接口分类模型,特别针对数据维度转换等关键难点提供可视化解析,并附完整代码实现。 阅读详情

[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中,放入的位置就是离result开始位置偏移了元素第二个数字后的位置。如下:
1.
people: [7,0]
插入到离开始位置偏移了0个距离的位置。
result: [[7,0]]
2.
people: [7,1]
插入到离开始位置偏移了1个距离的位置,即插入到[7,0]的后面。
result: [[7,0], [7,1]]
3.
people: [6,1]
插入到离开始位置偏移了1个距离的位置,即插入到[7,0]的后面。
result: [[7,0], [6,1], [7,1]]
4.
people: [5,0]
插入到离开始位置偏移了0个距离的位置,即插入到[7,0]的前面。
result: [[5,0], [7,0], [6,1], [7,1]]
5.
people: [5,2]
插入到离开始位置偏移了2个距离的位置,即插入到[7,0]的后面。
result: [[5,0], [7,0], [5,2], [6,1], [7,1]]
5.
people: [4,4]
插入到离开始位置偏移了4个距离的位置,即插入到[6,1]的后面。
result: [[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]

代码

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
        vector<pair<int, int>> res;
        sort(people.begin(), people.end(), [](pair<int, int> a, pair<int, int> b) {
            return (a.first > b.first) || (a.first == b.first && a.second < b.second);
        });

        for (auto p : people)
            res.insert(res.begin() + p.second, p);
        return res;
    }
};

int main() {
    vector<pair<int, int>> people = { make_pair(7,0), make_pair(4,4), make_pair(7,1), make_pair(5,0), make_pair(6,1), make_pair(5,2) }, res;
    Solution s;
    res = s.reconstructQueue(people);

    for (auto p : res) {
        cout << p.first << ' ' << p.second << endl;
    }

    system("pause");
    return 0;
}
Doris数据过期策略:自动清理历史数据 在数据的世界里,就像我们的房间会堆满各种东西一样,数据库也会积累大量的数据。随着时间的推移,很多历史数据可能不再经常被使用,但它们却占据着宝贵的存储空间。Doris是一款强大的数据库,为了让它能更高效地运行,合理地管理数据,我们就需要一种方法来自动清理那些不再需要的历史数据。本文的目的就是详细介绍Doris的数据过期策略,让大家知道如何利用这个策略来实现自动清理历史数据。范围涵盖了从基本概念到实际操作的各个方面。本文会先介绍一些和Doris数据过期策略相关的术语,让大家对一些专业词汇有个基本的了解。 阅读详情

相关推荐

蓝桥杯STM32G431RBT6学习——GPIO

蓝桥杯STM32G431RBT6学习——GPIO

weixin_44098974的博客 2243

LeetCode 406. Queue Reconstruction by Height 解题报告

LeetCode 406. Queue Reconstruction by Height 解题报告

骆小坑的填坑之旅 5432

从仿真到实践:两级直接耦合放大电路的静态工作点协同调试指南

本文详细解析了两级直接耦合放大电路的静态工作点协同调试方法,从仿真到实践提供系统指南。重点介绍了Rc2电阻调整技巧、集电极电位测量方法及常见问题排查,帮助工程师解决各级静态工作点相互影响的难题,提升模拟电路设计效率。

weixin_29189373的博客 130

Leetcode 406. Queue Reconstruction by Height 排队重构 解题报告

1 解题思想这道题的是让你重新排列一个序列。 总的来说,他给了你很多个打乱的2 原题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

MebiuW的专栏 4756

智慧工地算法视频分析服务器区域入侵检测AI视频分析技术在煤矿的实战应用

通过实时分析和处理井下视频资料,智慧矿山算法视频分析服务器不仅能够及时发现并预警人员违规行为和设备异常状况,还能够通过智能分析预防潜在的安全风险,从而显著提高煤矿的安全管理水平和生产效率。

EasyDarwin开源社区技术博客 568

用Python爬取公众号历史所有文章,看这篇就够了

手把手教你爬取公众号历史所有文章

u010522887的专栏 1万+

leetcode 406

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

tufushaoji的博客 202

数字信号的艺术演绎:用FPGA+DAC实现音乐合成器的核心原理

本文深入探讨了如何利用FPGA和DAC技术实现数字音乐合成器的核心原理,涵盖DDS架构、多波形合成、MIDI协议解析及动态包络控制等关键技术。通过详细的Verilog代码示例和硬件实现方案,展示了数字信号处理在音乐合成中的艺术演绎,为电子音乐创作提供了强大的硬件支持。

weixin_28256233的博客 392

Leetcode406

给了每个人的身高和前面>=他身高的人的个数。输出他们是怎么排的。 按照身高降序,人数升序排。 可以立即得到他们的排列。。。。 package com.leet; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.PriorityQu

dezhonger的专栏 1080

华为P812E光猫补全shell配置PON口模式

终于看到华为企业级的带2.5电口P812E横空出世了,相信很多发烧友也已经将此收入昂中。相信体验的同时,遇到的第一件事情就是配置PON口模式的问题,本文将带发烧基友解锁模式。

GUAIYU的博客 5772

Matlab:Matlab 软件学习之Matlab内置的各种系统的简介、案例应用(基于Simulink模糊控制仿真/二阶瞬态震荡电路案例)之详细攻略

选择左上角要编辑变量的图标,给定当前变量的论域Range,设置隶属函数类型type(八种隶属函数类型以供选择),最后选中某个隶属度函数(选中为红色),移动绘图区的每个隶属度函数的三个端点(竖向为权重)。(1)、首先在模糊规则编辑器左边选择一个输入变量,并选中它的一个语言值(隶属函数),然后编辑器右边选择一个输出变量,并选中它的一个语言值(隶属函数),然后将这种关系添加到模糊规则中。制定完成后,会形成模糊规则矩阵,系统会根据模糊输入量(如r1、r2),经过模糊规则(如45条),进而确定输出量(Y1、Y2)。

走向CTO之路 1132

LeetCode //C - 406. Queue Reconstruction by Height

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

Made in Code 1007

ultralytics.data.utils——utils.py子模块代码详读

ultralytics.data.utils——utils.py子模块代码详读

Together_CZ的博客 1730

LeetCode406. Queue Reconstruction by Height

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

叶卡捷琳堡的博客 968

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

老版QQ原生表情gif动态

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

LeetCode 406 Queue Reconstruction by Height

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

EricJeffrey的博客 308

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

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

【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

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

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

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

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

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...

fengran_mark的博客 250

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

店小不二的博客 597

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

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 206

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的博客 290

【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]513. Find Bottom Left Tree Value
下一篇: [LeetCode]28. Implement strStr()
charon____
博客等级 码龄11年 3粉丝 202原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值