F.cpp 572 B

123456789101112131415161718192021222324252627282930313233
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAX=100005;
  4. struct node{
  5. int s;
  6. int e;
  7. }a[MAX];
  8. int n;
  9. bool cmp(node x,node y)
  10. {
  11. return x.e<y.e;
  12. }
  13. int main()
  14. {
  15. while(cin>>n,n)
  16. {
  17. for(int i=0;i<n;i++)
  18. scanf("%d %d",&a[i].s,&a[i].e);
  19. sort(a,a+n,cmp);
  20. int temp=a[0].e,counter=1;
  21. for(int i=1;i<n;i++)
  22. {
  23. if(a[i].s>=temp)
  24. {
  25. counter++;
  26. temp=a[i].e;
  27. }
  28. }
  29. printf("%d\n",counter);
  30. }
  31. }