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. 华为交换机配置NTP服务端/客户端

    作者:邓聪聪 配置设备作为NTP服务器 单播客户端/服务器模式 # 配置NTP主时钟,层数为2. <HUAWEI> system-view [HUAWEI] ntp refclock-ma ...

  2. 关于CactiEZ自定义气象图的配置

    作者:邓聪聪 主要目录: Weathermap主目录:/var/www/html/plugins/weathermap 图片目录(包含背景图标文件):/var/www/html/plugins/wea ...

  3. /etc/shadow中密码段的生成方式

    why? 为什么要手动生成? 通常情况下,使用passwd命令即可以为用户设置密码,但是在某些情况下是需要先获得加密后的密码然后去操作的,比如,kickstart文件中的rootpw指令,ansibl ...

  4. 简单的三级联动demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. redis递减,过期返回值

    2017年4月24日 18:23:07 星期一 $key = 'abc'; $redis = IRedis::getInstance(); $a = $redis->setex($key, 1, ...

  6. mysql修改表、字段、库的字符集(转)

    原文链接:http://fatkun.com/2011/05/mysql-alter-charset.html MySQL中默认字符集的设置有四级:服务器级,数据库级,表级 .最终是字段级 的字符集设 ...

  7. 基于官方mysql镜像构建自己的mysql镜像

    参考文章:https://www.jb51.net/article/115422.htm搭建步骤 1.首先创建Dckerfile: 1 2 3 4 5 6 7 8 9 10 11 12 FROM my ...

  8. ueditor使用

    <html>    <head>        <meta charset="UTF-8">        <title></ ...

  9. mtu简单说明

    总结:本地的mtu值==网络设备的mtu值是最优的,一般本地和网络设备的默认值都是1500(字节),没什么特殊需求,尽量不要修改 一.什么是 MTU 值   1 从字面上来说,MTU 是英文 Maxi ...

  10. Hive学习01-基础常见问题

      理论: 什么是hive: 1. Hive旨在实现轻松的数据汇总,即时查询和分析大量数据. 2. 它提供了SQL,使用户可以轻松地进行临时查询,汇总和数据分析. 3. Hive可以使用用户定义函数( ...