There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 104 balloons.

An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstartand xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.

Example:

Input:
[[10,16], [2,8], [1,6], [7,12]] Output:
2 Explanation:
One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons). 计算不重叠的区间个数,[1, 2] 和 [2, 3] 在本题中算是重叠区间。 气球在一个水平数轴上摆放,可以重叠,飞镖垂直投向坐标轴,使得路径上的气球都会刺破。求解最小的投飞镖次数使所有气球都被刺破。 C++:
 bool compare(pair<int, int> a , pair<int, int> b){
return a.second < b.second ;
} class Solution {
public:
int findMinArrowShots(vector<pair<int, int>>& points) {
if (points.size() == ){
return ;
}
sort(points.begin() , points.end() , compare) ;
int cnt = ;
int end = points[].second ;
for(int i = ; i < points.size() ; i++){
if (points[i].first <= end){
continue ;
}
cnt++ ;
end = points[i].second ;
}
return cnt ;
}
};

452. Minimum Number of Arrows to Burst Balloons的更多相关文章

  1. 贪心:leetcode 870. Advantage Shuffle、134. Gas Station、452. Minimum Number of Arrows to Burst Balloons、316. Remove Duplicate Letters

    870. Advantage Shuffle 思路:A数组的最大值大于B的最大值,就拿这个A跟B比较:如果不大于,就拿最小值跟B比较 A可以改变顺序,但B的顺序不能改变,只能通过容器来获得由大到小的顺 ...

  2. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  3. [LeetCode] 452 Minimum Number of Arrows to Burst Balloons

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  4. 452. Minimum Number of Arrows to Burst Balloons——排序+贪心算法

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  5. 452. Minimum Number of Arrows to Burst Balloons扎气球的个数最少

    [抄题]: There are a number of spherical balloons spread in two-dimensional space. For each balloon, pr ...

  6. [LeetCode] 452. Minimum Number of Arrows to Burst Balloons 最少箭数爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  7. [LC] 452. Minimum Number of Arrows to Burst Balloons

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  8. 【leetcode】452. Minimum Number of Arrows to Burst Balloons

    题目如下: 解题思路:本题可以采用贪心算法.首先把balloons数组按end从小到大排序,然后让第一个arrow的值等于第一个元素的end,依次遍历数组,如果arrow不在当前元素的start到en ...

  9. 452 Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球

    在二维空间中有许多球形的气球.对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标.由于它是水平的,所以y坐标并不重要,因此只要知道开始和结束的x坐标就足够了.开始坐标总是小于结束坐标.平面 ...

随机推荐

  1. init级别

    新年第一天从温习记模糊的旧知识开始: init级别包含0-6: 0:关机 1:单用户(Root Only) 2:多用户(不包含Net File System 3:多用户(完全) 4:安全模式 5:桌面 ...

  2. MySQL主从1205报错【转】

    主从报错1205 Slave SQL thread retried transaction 10 time(s) in vain, giving up. Consider raising the va ...

  3. python的pymysql使用方法【转】

    前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持3.x版本. 本文测试python版本:2.6.6.m ...

  4. html5 file 上传文件

    <body> <header> <h2>Pure HTML5 file upload</h2> </header> <div clas ...

  5. shell监控自动备份是否成功(判断文件是否存在)

    作者:邓聪聪 在自动打包生成备份sql文件后,对运行情况做一个监控!  命令前加time,查看命令执行完成所用时间! FILE_DIR=/root/ DATE=$(date +%F) FILE_NAM ...

  6. windows网络相关的命令

    一.netstat命令 显示协议统计信息和当前 TCP/IP 网络连接. NETSTAT [-a] [-b] [-e] [-f] [-n] [-o] [-p proto] [-r] [-s] [-x] ...

  7. python操作三大主流数据库(9)python操作mongodb数据库③mongodb odm模型mongoengine的使用

    python操作mongodb数据库③mongodb odm模型mongoengine的使用 文档:http://mongoengine-odm.readthedocs.io/guide/ 安装pip ...

  8. YUV的数据格式

    一.YUV格式分为两大类:planar(平面)和packed(打包).planar格式,先连续存储所有像素点的Y分量,紧接着存储所有像素点的U,随后存储所有像素点的V.packed格式,每个像素点的Y ...

  9. 【原创】大叔经验分享(34)hive中文注释乱码

    在hive中查看表结构时中文注释乱码,分为两种情况,一种是desc $table,一种是show create table $table 1 数据库字符集 检查 mysql> show vari ...

  10. [Linux][HTTP] Cookie和Set-Cookie

    HTTP 请求报文通过Cookie字段通知服务端当前页面的域生效中的cookie; GET /my/login.php HTTP/1.1 Host: 192.168.88.207:91 Connect ...