标签:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; const int maxn = 10000 + 1; typedef struct { int start; int over; }point; point p[maxn]; const int cmp(const point a, const point b) { return a.over <= b.over; } int main() { int n; while (cin >> n) { memset(p, 0, sizeof(p)); for (int i = 0;i<n;i++) cin >> p[i].start >> p[i].over; sort(p, p + n, cmp); int cnt = 1; for (int i = 0;i<n;i++) { for (int j = i + 1;j<n;j++) { if (p[i].over <= p[j].start) { i = j; cnt++; continue; } } } cout << cnt << endl; } return 0; }
第1行:1个数N,线段的数量(2 <= N <= 10000) 第2 - N + 1行:每行2个数,线段的起点和终点(-10^9 <= S,E <= 10^9)
输出最多可以选择的线段数量。
3 1 5 2 3 3 6
2
标签:
原文地址:http://www.cnblogs.com/zoudajia/p/5508580.html