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\) 表示 ...
随机推荐
- Angular 学习笔记 ( CDK - Observers )
<div class="projected-content-wrapper" (cdkObserveContent)="projectContentChanged( ...
- Oracle update 执行更新操作后的数据恢复
操作数据库,经常会出现误操作,昨天执行的更新操作之后发现更新错了,只能想办法数据恢复了,现在整理一下 第一步:查询执行更新操作的时间 select r.FIRST_LOAD_TIME,r.* from ...
- centos6.5时间相关
时间同步 service ntpdate start 开启网络时间同步
- 初学Java Web(4)——Servlet学习总结
经过一段时间的学习,对于Servlet有了新的不一样的见解,在这里做一下总结,将近来学习到的知识总结一下. Servlet 的请求流程 浏览器发出请求:http://localhost:80/xxx1 ...
- Spark:导入数据到oracle
方案一: //overwrite JdbcDialect fitting for Oracle val OracleDialect = new JdbcDialect { override def c ...
- POJ-1062 昂贵的聘礼---Dijkstra+枚举上界
题目链接: https://vjudge.net/problem/POJ-1062 题目大意: 中文题 思路: 1是终点,可以额外添加一个源点0,0到任意一节点的距离就是这个点的money,最终求的是 ...
- matlab coder 工具箱使用教程
之前一直听说matlab代码可以转C和C++代码,但是一直都没有时间尝试,最近闲着无聊,就想来试试如何转换,上网查了很多资料,照着做下去,发现都有一些问题,之后自己琢磨了很久,终于将一个很简单的例子给 ...
- java String的各种方法及操作
No. 方法名称 功能 字符与字符串 01 public String(char[] value) 将字符数组中所有内容变为字符串 02 public String(char[] value,int ...
- [HNOI 2011]XOR和路径
Description 给定一个无向连通图,其节点编号为 1 到 N,其边的权值为非负整数.试求出一条从 1 号节点到 N 号节点的路径,使得该路径上经过的边的权值的“XOR 和”最大.该路径可以重复 ...
- 【SPOJ839】Optimal Marks 网络流
You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...