提交时间:2023-11-04 13:39:39

运行 ID: 108916

#include <bits/stdc++.h> using namespace std; const int N=200+10; const int INF=0x3f3f3f3f; int n,ans; struct TVshow{ int s,e; }a[N]; bool cmp(TVshow x,TVshow y) { if(x.e==y.e) { return x.s<=y.s; } return x.e<y.e; } int main() { while(cin>>n) { if(n==0) { break; } ans=0; for(int i=1;i<=n;i++) { cin>>a[i].s>>a[i].e; } sort(a+1,a+n+1,cmp); int l=-1; for(int i=1;i<=n;i++) { if(a[i].s >= l) { l=a[i].e; ans++; } } cout<<ans; } return 0; }