按照结束时间排序即可。
C++ 代码
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vector<pii> order(n);
for (int i=0;i<n;++i) cin>>order[i].first>>order[i].second;
sort(order.begin(),order.end(),[&](const auto& a,const auto& b){ return a.second<b.second;});
int curTick=0;
int ans=0;
for (auto& o:order){
if (o.first>curTick) {
curTick=o.second;
ans++;
}
}
cout<<ans<<endl;
}