Description:
选若干个区间,使得两两不重合,求最大的区间个数
Code
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
pair<int, int> itv[1100];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &itv[i].second, &itv[i].first);
}
sort(itv, itv + n);
int ans = 0, ed = -1;
for (int i = 0; i < n; ++i) {
if (ed <= itv[i].second) {
ans++;
ed = itv[i].first;
}
}
printf("%d", ans);
return 0;
}