You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
686 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 110;
const int M = 1000010;
int n, ans, finish;
struct node {
int l, r;
} con[M];
//按右端点排序
bool cmp(const node &a, const node &b) {
return a.r <= b.r;
}
int main() {
cin >> n;
//输入
for (int i = 1; i <= n; i++) cin >> con[i].l >> con[i].r;
//排序
sort(con + 1, con + 1 + n, cmp);
for (int i = 1; i <= n; i++)
if (finish <= con[i].l) //如果finish小于遍历于的线段左端点那么可用。这句话是核心
ans++, finish = con[i].r; //迭代的过程
cout << ans << endl;
return 0;
}