Files
python/TangDou/LuoGuBook/P1803.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
686 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}