@[xibaby](/user/995569) ACcode
```
#include <bits/stdc++.h>
using namespace std;
int n,sum=0,f=0;
struct node
{
int l,r;
}con[10000000];
bool cmp(node a,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(f<=con[i].l)
sum++,f=con[i].r;
cout<<sum;
return 0;
}
```
by kkksbsbsbssb @ 2023-08-28 23:46:46
那个b实在排序过后再算啊
by xiaoyang111 @ 2023-08-28 23:48:39
你的代码改了就是这个:
```cpp
#include<bits/stdc++.h>
using namespace std;
struct w{
int a,b;
}c[1000001];
bool cmp(w x,w y){
return x.b<y.b;
}
int n,s=1;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&c[i].a,&c[i].b);
sort(c+1,c+n+1,cmp);
int b=c[1].b;
for(int i=2;i<=n;i++)
if(c[i].a>=b){
s++; b=c[i].b;
}
printf("%d",s);
return 0;
}
```
by xiaoyang111 @ 2023-08-28 23:49:17
感谢二位,已过~
by xibaby @ 2023-08-28 23:56:20