zoukankan      html  css  js  c++  java
  • 406. Queue Reconstruction by Height

    https://www.cnblogs.com/grandyang/p/5928417.html

    https://www.cnblogs.com/liziran/p/6106534.html
    个子高的位置排好后,再怎么对个子矮的排,都不会影响个子高的人的相对位置

    贪心的思想

    class Solution {
    public:
        vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
            sort(people.begin(),people.end(),cmp);
            for(int i = 0;i < people.size();i++){
                if(people[i].second != i){
                    auto p = people[i];
                    people.erase(people.begin() + i);
                    people.insert(people.begin() + p.second,p);
                }
            }
            return people;
        }
        static bool cmp(pair<int,int> a,pair<int,int> b){
            if(a.first > b.first || (a.first == b.first && a.second < b.second))
                return true;
            else
                return false;
        }
    };
  • 相关阅读:
    1059 C语言竞赛
    1058 选择题
    1057 数零壹
    1056 组合数的和
    1055 集体照
    Mysql--分库分表
    Mysql--改表结构
    Mysql--开始阶段
    Mysql--常用语句
    Mysql--grant授权
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/10498795.html
Copyright © 2011-2022 走看看