fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. struct program {
  5. int start;
  6. int end;
  7. bool operator <(const program t) const{
  8. if(this->start !=t.start)
  9. return this->start < t.start;
  10. else
  11. return this->end < t.end;
  12. }
  13. };
  14. /*
  15. bool operator <(const program &a, const program &b)
  16. {
  17.   if(a.start !=b.start)
  18.   return a.start <b.start;
  19.   else
  20.   return a.end <b.end;
  21. }
  22. */
  23. const int N = 101;
  24. program list[N];
  25.  
  26. int main()
  27. {
  28. int n, i, total, mark;
  29. // freopen("in.txt","r",stdin);
  30. while(scanf("%d",&n),n)
  31. {
  32. for(i=0;i<n;i++)
  33. scanf("%d%d",&list[i].start, &list[i].end);
  34. sort(list,list+n);
  35. //for(i=0;i<n;i++) printf("%d %d\n", list[i].start, list[i].end);
  36. total = 1; mark = list[0].end;
  37. for(i=1;i<n;i++)
  38. if(mark <=list[i].start)
  39. {
  40. mark = list[i].end;
  41. total++;
  42. }else
  43. {
  44. if(mark >list[i].end)
  45. mark = list[i].end;
  46. }
  47. printf("%d\n",total);
  48. }
  49. return 0;
  50. }
Runtime error #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Standard output is empty