fork download
  1. #include <bits/stdc++.h>
  2. #define FIN "spectacole.in"
  3. #define FOUT "spectacole.out"
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. typedef struct {
  8. int start,
  9. end;
  10. } Interval;
  11.  
  12. bool cmp(Interval I1, Interval I2) {
  13. return I2.end > I1.end;
  14. }
  15.  
  16. int main(int argc, char const *argv[]) {
  17.  
  18. int n, x, y;
  19. Interval I;
  20. std::vector<Interval> spectacles;
  21.  
  22. //freopen(FIN, "r", stdin);
  23. //freopen(FOUT, "w", stdout);
  24.  
  25. std::cin>>n;
  26. for(int i = 0; i < n; ++i) {
  27. std::cin>>x>>y;
  28. I.start = x;
  29. I.end = y;
  30. spectacles.push_back(I);
  31. }
  32.  
  33. //for(auto x: spectacles) {
  34.  
  35. //std::cout<<x.start<<" "<<x.end<<std::endl;
  36. //}
  37.  
  38. //std::cout<<std::endl;
  39.  
  40. sort(spectacles.begin(), spectacles.end(), cmp);
  41.  
  42. //for(std::vector<Interval>::iterator it = spectacles.begin(); it!=spectacles.end(); ++it)
  43.  
  44. //std::cout<< (*it).start<<" "<<(*it).end<<"\n";
  45.  
  46. int curr = spectacles[0].end;
  47.  
  48. int i = 1;
  49.  
  50. int count = 1;
  51.  
  52. while (i < n){
  53.  
  54. if(spectacles[i].start >= curr) {
  55.  
  56. curr = spectacles[i].end;
  57.  
  58. count++;
  59. }
  60. i++;}
  61.  
  62. std::cout<<count;
  63.  
  64. return 0;
  65. }
  66.  
Success #stdin #stdout 0.01s 5296KB
stdin
10
5 14
14 17
8 13
13 15
15 17
3 6
4 7
6 9
11 14
10 11
stdout
5