`

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

 

分享到:
评论

相关推荐

    NUMERICAL SOLUTION OF HYPERBOLIC PARTIAL DIFFERENTIAL EQUATIONS

    Of course, the numerical methods in this book can be used to solve linear hyperbolic conservation laws, but our methods will not be as fast or accurate as possible for these problems. If you are only...

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

    Automatic Target Recognition in High Resolution SAR Image Based on Electromagnetic Characteristics

    The method of affine transform is used to extract the invariant features of the image contour of several types of airplanes. The image contours of several airplanes are real-time acquired by using ...

    Computers as Components_ Principles of Embedded Computing System Design. 4th

    a chapter on automobiles and airplanes (Chapter 9) explores networked embedded systems in the context of vehicles as well as covering several examples in safety and security; and the embedded ...

    故障树的综述

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

    程序开发物理学2nd

    Apply concepts to real-world problems: model the behavior of boats, airplanes, cars, and sports balls Enhance your games with digital physics, using accelerometers, touch screens, Gps, optical ...

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

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

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

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

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

    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

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

    Airplanes Wallpapers New Tab-crx插件

    在浏览器的“新标签”页面中享受定制的飞机壁纸 还包括客机,airbus380,喷气飞机的超高清背景。 不可能不沉迷于他们! ☆你从飞机主题中得到什么? 有了这个免费的扩展程序,您可以通过每个新选项卡获得高清质量的...

    “中软国际杯”湖南省第四届大学生程序设计大_高教学会计算机教育专业委员会.mht

    The system traces all flying objects within a certain radius of action: airplanes, helicopters, parachutists, etc. It is assumed that objects move in straight lines with constant speeds, and their ...

    fiwi.zip_MCA_fiwi

    In airplanes, wireless communications and Internet access are still not available . The increasing demand for offering communication services to passengers using mobile phones on aircraft. Allowing a ...

Global site tag (gtag.js) - Google Analytics