题目链接:区间选点
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
int n;
struct Range
{
int l, r;
bool operator< (const Range &W) const
{
return r < W.r;
}
}range[N];
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i ++)
{
int l, r;
scanf("%d%d", &l, &r);
range[i] = {l, r};
}
sort(range, range + n);
// res: 当前选择的点的数量 ed: 上一个点的下标
int res = 0, ed = -2e9;
for(int i = 0; i < n; i ++)
if(range[i].l > ed)
{
res ++;
ed = range[i].r;
}
cout << res << endl;
return 0;
}