`

LintCode - Number of Airplanes in the Sky

 
阅读更多

Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most?

Example

For interval list [[1,10],[2,3],[5,8],[4,7]], return 3

Note

If landing and flying happens at the same time, we consider landing should happen at first.

将所有区间的start与end放在一起排序,但是要标记其是属性,然后统一排序,问题就转化成了括号匹配嵌套的问题了(最大有多少层括号嵌套,比如说((()))就是一个3层嵌套,()(()))最大嵌套是2),这里start相当于左括号,end相当于右括号,只要用一个cnt来记录,遇到start就加1,遇到end就减1,记录过程中的最大值就是答案。

 

int countOfAirplanes(vector<Interval> &airplanes) {
    vector<pair<int,bool>> v;
    for(auto& i:airplanes) {
        v.push_back(make_pair(i.start, true));
        v.push_back(make_pair(i.end, false));
    }
    sort(v.begin(), v.end());
    int cnt = 0, most = 0;
    for(auto& p:v) {
        if(p.second) cnt++;
        else cnt--;
        most = max(most, cnt);
    }
    return most;
}

  

Reference:

http://www.cnblogs.com/easonliu/p/4504647.html

 

分享到:
评论

相关推荐

    ApplicationLightweightingTechnology2MilitaryVehicles

    The committee’s work was aided greatly by a number of people. We are grateful to our sponsor, the U.S. DoD’s Reliance 21 Materials and Processing Team, and to the experts who took the time to speak ...

    故障树的综述

    tree analysis, providing an in-depth overview of the state-of-the-art in FTA. Concretely, we review standard fault trees, as well as extensions such as dynamic FT, repairable FT, and extended FT. For ...

    AVG 破解版

    3. The Licensor reserves the right to block accounts/license codes that have not been paid for by the user in due time or that stood out through a very high number of updates until settlement of the ...

    FDC1.2版本用户手册

    The model currently has been configured for the DeHavilland DHC-2 'Beaver' and can be adapted for other kinds of airplanes, thanks to its modular design. It can be accessed via the graphical user-...

    计算几何讲义.pdf

    Geometric modeling deals with the mathematical representation of curves, surfaces, and solids necessary in the definition of complex physical or engineering objects. The associated field of ...

    rigs-of-rods:Rigs of Rods 软体物理模拟器的主要开发库

    Rigs of Rods 是一个自由/自由的软体物理模拟器,主要用于模拟车辆物理。 软体物理系统基于质量-弹簧-阻尼器理论。 有关 Rigs of Rods 提供的功能的简单概述,请参阅 预告片: 支持的平台: 视窗 Linux 进一步的...

    内蒙古鄂尔多斯市达拉特旗八年级英语下册Module6HobbiesUnit2Hobbiescanmakeyougrowasape

    - 例句:I saw her running in the park. ### 二、语法点解析 1. **make 的用法** - 作为使役动词,"make" 的基本用法有两种: - make + sb./sth. + do sth.:使某人/某物做某事。 - 例句:The teacher made ...

    高中词汇(四级常用)

    - **例句**:The United States of America is one of the largest economies in the world. #### amusement 娱乐,消遣 - **定义**:提供乐趣或娱乐的活动。 - **例句**:Going to amusement parks can be a fun ...

    Making Embedded Systems

    After seeing embedded systems in medical devices, race cars, airplanes, children's toys, and gunshot location systems, I've found a lot of commonalities. There are a lot of things I wish I knew then ...

    北师大版高中英语选修7(部分单词表)

    - **例句**:“In case of emergency, please use the nearest exit.”(紧急情况下,请使用最近的出口。) #### dilemma - **含义**:困境;进退两难的窘境 - **例句**:“He faced a dilemma between choosing ...

    Study on the transmission characteristic of terahertz pulse through packing materials

    Terrorism has become an international problem in recent years as evidenced by toxins mailed through the post, liquid explosives planted in airplanes, and so on. Clearly, the security screening of ...

    课时讲练通高中英语Module精PPT课件.pptx

    - `Don't look out of the window.` 意为不要看向窗外,这里的`out`指的是向外部看的动作。 - `The room looks out on the sea.` 描述房间的视角,表示房间面向大海。 5. **词汇拓展**: - `look after`:照顾,...

    The Slow Winter-计算机科学

    J a m e s m i c k e n sA ccording to my dad, flying in airplanes used to be fun. You could smoke on the plane, and smoking was actually good for you. Every-body was attractive, and there were no fees ...

    Web Design Blueprints(PACKT,2016)

    The book delivers simple instructions on how to design and build modern Web using the latest trends in web development. You will learn how to design responsive websites, created with modern Flat User ...

    (安徽专用)2014届高考英语一轮复习方案 作业手册(8)模块3 Unit 8 Adventure(含解析) 北师大版

    5. "The data is limited in terms of both ________ and ________." "in terms of" 表示“在...方面”,"quality and quantity" 指数据的质量和数量,都有限。 【知识点四:计算机术语与动词短语】 6. "The ...

    Airplanes HD Wallpapers New Tab Theme-crx插件

    喜欢各种飞机吗? 如果您这样做,请立即获取...隐私政策:https://coolstart.com/privacy-policy使用条款:https://coolstart.com/terms-of-use如何卸载:https://coolstart.com/how-to-uninstall 支持语言:English

    高中英语 Module grammar and function 外研必修PPT课件.pptx

    学习者可以了解到如何讨论和评价这些预测,例如,"The most amusing one: Clothes and Robots in the house" 和 "The most ridiculous one: Airplanes and The Beatles"。 2. **句子翻译**:课件中包含了对英文句子...

    StateWorks Studio

    StateWORKS is the only Software Engineering method that uses design practices as sound as those used to engineer hardware, bridges and airplanes: StateWORKS takes the coding out of software and truly ...

Global site tag (gtag.js) - Google Analytics