- [伴随编程] 实现不相交的线段
随便发个题解啊
- 2024-3-10 20:20:06 @
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+1;
struct node{
int l,r;
};
node a[N];
int ans,n;
bool cmp(node a,node b){
return a.r<b.r;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].l>>a[i].r;
}
sort(a+1,a+1+n,cmp);
node tmp=a[1];
ans++;
for(int i=2;i<=n;i++){
if(a[i].l>=tmp.r){
ans++;
tmp.r=a[i].r;
}
}
cout<<ans;
return 0;
}
老师我发的是讨论,不是题解
0 comments
No comments so far...
Information
- ID
- 1039
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 45
- Accepted
- 18
- Uploaded By