Lintcode391 Number of Airplanes in the Sky solution 题解
【题目描述】
Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most?
Notice:If landing and flying happens at the same time, we consider landing should happen at first.
给出飞机的起飞和降落时间的列表,用 interval 序列表示. 请计算出天上同时最多有多少架飞机?
【注】如果多架飞机降落和起飞在同一时刻,我们认为降落有优先权。
【题目链接】
www.lintcode.com/en/problem/number-of-airplanes-in-the-sky/
【题目解析】
1) 将start和end时间分别保存在两个list中,并对两个list排序。
2) 从两个list的第一个元素开始比较,若start小于end,则天上增加一架飞机,并将start进一位,反之则天上减少一架飞机,并将end进一位。记录每次增加飞机后天上飞机数量的最大值。
3) 当start遍历完成时,返回此时最大值。
【参考答案】
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
Lintcode391 Number of Airplanes in the Sky solution 题解的更多相关文章
- Number of Airplanes in the Sky
Given an interval list which are flying and landing time of the flight. How many airplanes are on th ...
- LintCode: Number of Airplanes in the Sky
C++ (1)把interval数组中的所有start和所有end放在同一个数组中,然后进行排序,遇到start就起飞一架飞机,遇到一架end就降落一架飞机,所以start有个+1属性,end有个-1 ...
- Lintcode249 Count of Smaller Number before itself solution 题解
[题目描述] Give you an integer array (index from 0 to n-1, where n is the size of this array, data value ...
- Lintcode248 Count of Smaller Number solution 题解
[题目描述] Give you an integer array (index from 0 to n-1, where n is the size of this array, value from ...
- Lintcode401 Kth Smallest Number in Sorted Matrix solution 题解
[题目描述] Find the kth smallest number in at row and column sorted matrix. 在一个排序矩阵中找从小到大的第 k 个整数. 排序矩阵的 ...
- Lintcode360 Sliding Window Median solution 题解
[题目描述] Given an array of n integer, and a moving window(size k), move the window at each iteration f ...
- Lintcode247 Segment Tree Query II solution 题解
[题目描述] For an array, we can build a Segment Tree for it, each node stores an extra attribute count t ...
- Lintcode373 Partition Array by Odd and Even solution 题解
[题目描述] Partition an integers array into odd number first and even number second. 分割一个整数数组,使得奇数在前偶数在后 ...
- CF742B Arpa's obvious problem and Mehrdad's terrible solution 题解
Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示 ...
随机推荐
- Linux实战案例(4)CentOS清除用户登录记录和命令历史方法
CentOS清除用户登录记录和命令历史方法 清除登陆系统成功的记录[root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信 ...
- 【iOS】UIViewController基类的实现
继承是面向对象编程语言的三大特性之一,写好基类会给App的开发带来极大的方便.在iOS开发中,一般一个页面就对应一个ViewController,ViewController在开发中用的也很多,写一个 ...
- Python学习之参数
参数 # coding=utf-8 # 函数的参数 def power(x): return x * x; print power(5) 修改后 def power_1(x,n=2): #默认参数可以 ...
- python基础(常用内容)
python基础(常用内容) 机器数: 一个数在计算机中的二进制表示形式就是机器数. 例如: +3用机器数表示就用<00000011>表示 -3用机器数表示就用<10000011&g ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...
- HDU-1850 Being a Good Boy in Spring Festival---尼姆博奕的运用
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1850 题目大意: 中文题: 思路: 传送门:尼姆博奕 #include<iostream> ...
- hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意: 求递增子序列最大和 思路: 直接dp就可以求解,dp[i]表示以第i位结尾的递增子 ...
- 06、NetCore2.0依赖注入(DI)之整合Autofac
06.NetCore2.0依赖注入(DI)之整合Autofac 除了使用NetCore2.0系统的依赖注入(DI)框架外,我们还可以使用其他成熟的DI框架,如Autofac.Unity等.只要他们支持 ...
- 四,前端---constructor与prototype
这里对于constructor 和 prototype做一个简单的介绍,旨在让大家有一个简单的了解与认识 1:定义与用法 prototype:属性使您有能力向对象添加属性和方法. constructo ...
- python包安装和使用机制
python语言的魅力之一就是大量的外置数据包,能够帮助使用者节省很多时间,提高效率.模块下载和引用是最常见的操作,现在解析内部的原理和背后发生的故事,做到心里有数. 导航: 基本定义 模块使用 模块 ...