This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#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;