AcWing 803. 区间合并
原题链接
简单
作者:
a行君
,
2024-04-09 19:29:56
,
所有人可见
,
阅读 2
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100100;
struct PII{
int first;
int second;
bool operator< (const PII& x)const{
if(first==x.first){
return second<x.second;
}
return first<=x.first;
}
}p[N];
int main()
{
int n;
cin>>n;
for (int i = 0; i < n; i ++ ){
cin >> p[i].first>>p[i].second;
}
sort(p,p+n);
int ans=1,maxr = p[0].second;
for (int i = 1; i < n; i ++ ){
if(maxr<p[i].first){
ans++;
}
maxr = max(maxr,p[i].second);
}
cout << ans;
}