51nod 2级算法题-1133
来源:互联网 发布:usb端口禁用破解 编辑:程序博客网 时间:2024/06/17 06:59
1133 不重叠的线段
X轴上有N条线段,每条线段有1个起点S和终点E。最多能够选出多少条互不重叠的线段。(注:起点或终点重叠,不算重叠)。例如:[1 5][2 3][3 6],可以选[2 3][3 6],这2条线段互不重叠。
Input
第1行:1个数N,线段的数量(2 <= N <= 10000)第2 - N + 1行:每行2个数,线段的起点和终点(-10^9 <= S,E <= 10^9)
Output
输出最多可以选择的线段数量。
Input示例
31 52 33 6
Output示例
2
贪心模板就好了
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <queue>#include <stack>using namespace std;#define endl "\n"const int maxn=10000+100;struct Line{ int l; int r;}L[maxn];bool cmp(Line A,Line B){ if(A.r==B.r){ return A.l<B.l; } return A.r<B.r;}int main (){ ios::sync_with_stdio(false); int a=L[0].r; for(int i=1;i<n;i++){ if(L[i].l>=a){ a=L[i].r; sum++; } } cout<<sum<<endl; return 0;}
0 0
- 51nod 2级算法题-1133
- 51nod 2级算法题-1007
- 51nod 2级算法题-1010
- 51nod 2级算法题-1014
- 51nod 2级算法题-1050
- 51nod 2级算法题-1062
- 51nod 2级算法题-1092
- 51nod 2级算法题-1095
- 51nod 2级算法题-1119
- 51nod 2级算法题-1126
- 51nod 2级算法题-1279
- 51nod 2级算法题-1315
- 51nod 2级算法题-1428
- 51 nod 1133 二级算法题 贪心
- 【模拟】1432 独木舟【51nod】【难度:2级算法题】
- 51nod 1级算法题
- 51nod 3级算法题-1065
- 51nod 5级算法题
- Android实现简单购物车
- php面试题之三——PHP语言基础(基础部分)
- java.math.BigDecimal cannot be cast to java.lang.String
- 视图
- 跨域
- 51nod 2级算法题-1133
- 微信开发第一课
- JAVA冒泡排序(递归以及非递归)
- iOS 史上最全的 UITextView 实现 placeHolder 占位文字 的N种方法
- 程序员必备的代码审查(Code Review)清单
- Unity给力插件之ShaderForge(二)
- 写了几年的css,今天才知道其中奥秘
- Android 网络请求
- Eclipse中将Java项目转换成Web项目的方法