#include<bits/stdc++.h> using namespace std; const int N=1e5+10; int n; struct Range{ int l;int r; bool operator < (const Range & w)const { return r<w.r; } }range[N]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ int l,r; cin>>l>>r; range[i]={l,r}; } sort(range,range+n); int res=0,ed=-2e9; for(int i=0;i<n;i++){ if(range[i].l>ed){ res++; ed=range[i].r; } } cout<<res<<endl; return 0; }
标签:选点,const,int,ed,range,res,区间,贪心 From: https://www.cnblogs.com/aixin52129211/p/17354011.html