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. 【C++】一篇文章,让你不再害怕指针

    在C++中,比较难以理解的就是指针,最常用的也是指针.这篇文章,结合我的所学,所看,来谈谈C++中的指针 指针是什么 指针是一个特殊的变量,指向内存中的一个地址.它具有四个要素: 指针类型:即指针本身 ...

  2. VC里判断系统是不是64bit

    不过,理论上来说,也可以用一个int的大小作为参考,判断是32位还是64位.sizeof(int) == 4 //32位系统.sizeof(int) == 8 //64位系统. 也可以使用函数如下: ...

  3. Alpha冲刺(9/10)

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺倒计时之9 团队部分 后敬甲(组长) 过去两天完成了哪些任务 答辩准备中 和大佬们跟进进度 接下来的计划 准备答辩 ...

  4. bash的快捷键、特殊参数、历史命令、相关文件

    bash快捷键 Emacs风格 ctrl+p: 方向键 上 ↑ ctrl+n: 方向键下 ↓ ctrl+b: 方向键 ← alt+f: 光标右移一个单词 ctrl+f :方向键 → alt+b: 光标 ...

  5. Day7--------------虚拟机网络服务

    1.桥接 连接到本地的网卡,把本机的网卡看作是虚拟交换机 ping ip地址 arping -i eth0 192.168.11.11 返回物理MAC地址             #可以检查是否有重复 ...

  6. CSS 三角形与圆形

    1. 概述 1.1 说明 通过边框(border)的宽度与边框圆角(border-radius)来设置所需的三角形与圆形. 1.2 边框 宽高都为0时,边框设置的不同结果也不同,如下: 1.四个边框都 ...

  7. Codeforces 1091E New Year and the Acquaintance Estimation [图论]

    洛谷 Codeforces 思路 有一个定理:Erdős–Gallai定理. 然后观察样例,可以猜到答案必定是奇偶性相同的一段区间,那么二分左右端点即可. 定理和这个猜测暂时都懒得学/证,留坑. #i ...

  8. jemter 新增sha256函数

    1  https://blog.csdn.net/y100100/article/details/80701049 2  https://blog.csdn.net/y100100/article/d ...

  9. TeamLab安装及使用

    http://blog.csdn.net/crazin/article/details/9529061 最近想装个项目管理管理系统方便项目管理,调研了下这方面开源的软件还是比较多的,国内的有禅道,试用 ...

  10. python之vscode中手动选择python解释器(mac)

    要选择特定的解释器,请从命令选项板(⇧⌘P)调用Python:Select Interpreter命令. 更详细请看:http://www.cnblogs.com/it-tsz/p/9312151.h ...