Codevs 1214 线段覆盖
2016-10-23 11:25
369 查看
1214 线段覆盖
6 3
1 3
2 5
题目描述 Description
给定x轴上的N(0<N<100)条线段,每个线段由它的二个端点a_I和b_I确定,I=1,2,……N.这些坐标都是区间(-999,999)的整数。有些线段之间会相互交叠或覆盖。请你编写一个程序,从给出的线段中去掉尽量少的线段,使得剩下的线段两两之间没有内部公共点。所谓的内部公共点是指一个点同时属于两条线段且至少在其中一条线段的内部(即除去端点的部分)。
输入描述 Input Description
输入第一行是一个整数N。接下来有N行,每行有二个空格隔开的整数,表示一条线段的二个端点的坐标。
输出描述 Output Description
输出第一行是一个整数表示最多剩下的线段数。
样例输入 Sample Input
36 3
1 3
2 5
样例输出 Sample Output
2数据范围及提示 Data Size & Hint
0/* 6 1 2 2 3 4 5 5 6 1 30 100 200 */ #include<cstdio> #include<iostream> #include<algorithm> using namespace std; struct node { int x; int y; bool operator < (node b) const { return y<b.y; } }; node a[101]; int n,ans,x,y; inline void read(int&x) { int f=1;x=0;char c=getchar(); while(c>'9'||c<'0') {if(c=='-') f=1;c=getchar();} while(c>='0'&&c<='9') x=10*x+c-48,c=getchar(); x=x*f; } int main() { read(n); for(int i=1;i<=n;i++) { read(x),read(y); if(x>y) swap(x,y); a[i].x=x;a[i].y=y; } sort(a+1,a+1+n); int t=a[1].y; for(int i=2;i<=n;i++) { if(a[i].x>=t) { ans++; t=a[i].y; } } printf("%d\n",ans+1); return 0; }
相关文章推荐
- codevs 1214 线段覆盖/1643 线段覆盖 3
- codevs 1214 线段覆盖 贪心 解题报告
- CODE[VS]_1214 线段覆盖问题
- codevs 1214 线段覆盖(贪心 or dp)
- 【基础练习】【贪心】codevs1214 线段覆盖题解
- codevs1214 线段覆盖(贪心)
- codevs1214 线段覆盖(贪心)
- CODE[VS] 1214 线段覆盖
- CODE[VS] 1214 线段覆盖
- codevs1214 线段覆盖
- 【贪心】【排序】【codevs 1214】线段覆盖
- codevs1214 线段覆盖
- CODE[VS] 天梯 1214 线段覆盖
- 【基础练习】【贪心】codevs1214 线段覆盖题解
- codevs 1214线段覆盖
- [Codevs] 1214 线段覆盖
- 洛谷1791/CODEVS1214线段覆盖
- 【20171111】 Codevs 1214 线段覆盖
- Codevs 1214 线段覆盖
- codevs 1214 线段覆盖