2 solutions
-
0
#include<bits/stdc++.h> using namespace std; struct PII{ int x,y; }; bool cmp(PII a,PII b) { if(a.y<b.y) return 1; return 0; } int main() { int n; cin>>n; vector<PII> v(n); for(int i=0;i<n;i++) { cin>>v[i].x>>v[i].y; } sort(v.begin(),v.end(),cmp); //按照y从大到小排序 int res=1,ed=v[0].y; for(int i=1;i<n;i++) { if(ed<v[i].x) //出现缝隙 { res++; ed=v[i].y; //选择当前区间最右边的点 } } cout<<res; return 0; }
Information
- ID
- 246
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 39
- Accepted
- 18
- Uploaded By