@[tangfanhao](/user/939326) 请检查变量初始化,您的的代码绝对有 UB。
by xiaoshumiao @ 2024-02-02 11:53:24
[AC记录](https://www.luogu.com.cn/record/145741404)
[WA记录](https://www.luogu.com.cn/record/145741427)
by tangfanhao @ 2024-02-02 11:55:02
@[tangfanhao](/user/939326) 开O2可过
by wunaidedanjuan @ 2024-02-02 11:57:14
@[xiaoshumiao](/user/1008513)
萌新看不懂(悲)
by tangfanhao @ 2024-02-02 11:57:53
@[tangfanhao](/user/939326) 放一下代码。
by xiaoshumiao @ 2024-02-02 11:58:45
@[xiaoshumiao](/user/1008513)
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,ans,nm;
struct node{
int a,b;
}a[1000000];
bool cmp(node x,node y){
return x.b<y.b;
}
int main(){
// freopen("p1803_8.in","r",stdin);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].a>>a[i].b;
}
sort(a+1,a+1+n,cmp);
ans=1;
nm=a[1].b;
for(int i=2;i<=n;i++){
if(a[i].a>=nm){
ans++;
nm=a[i].b;
}
}
cout<<ans;
return 0;
}
```
by tangfanhao @ 2024-02-02 11:59:23
@[tangfanhao](/user/939326) 你数组开小了吧。
by xiaoshumiao @ 2024-02-02 12:04:02
[数组开大后](https://www.luogu.com.cn/record/145744153)
by xiaoshumiao @ 2024-02-02 12:04:40
@[xiaoshumiao](/user/1008513)
谢谢dalao
waw
by tangfanhao @ 2024-02-02 14:02:46