思路

排序 + 贪心

过程

alt

代码

#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 2e5 + 10;

PII p[N];
int n;

int main()
{
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    int end = p[0].second, ans = 1;
    for(int i = 1;i < n;i ++)
    {
        if(p[i].first < end) end = min(end, p[i].second);
        else
        {
            end = p[i].second;
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}