提交时间:2024-03-02 09:22:54
运行 ID: 133796
#include<bits/stdc++.h> using namespace std; const int N=2e3+10; int n; struct TV{ int st,ed; }a[N]; bool cmp(TV x,TV y) { if(x.st!=y.st)return x.ed<y.ed; else return x.st<y.st; } int main() { while(cin>>n && n) { for(int i=1;i<=n;++i) { cin>>a[i].st>>a[i].ed; } sort(a+1,a+n+1,cmp); int end=0,ans=0; for(int i=1;i<=n;++i) { if(end<=a[i].st) { end=a[i].ed; ans++; } else { if(a[i].ed<end) { end=a[i].ed; } } } cout<<ans<<'\n'; } return 0; }