artemgf

Научная конференция

May 5th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <algorithm>
  8. #include <string>
  9. #include <math.h>
  10. #include <vector>
  11. #include <cmath>
  12. #include <sstream>
  13.  
  14. using namespace std;
  15.  
  16. struct time
  17. {
  18.     long long end, start;
  19. };
  20.  
  21. bool operator<(time p1, time p2)
  22. {
  23.     if (p1.end == p2.end)
  24.         return p1.start < p2.start;
  25.     else
  26.         return p1.end < p2.end;
  27. }
  28.  
  29. int main()
  30. {
  31.     vector<time> times;
  32.     long long prom1, prom2, n, sc = 1;
  33.  
  34.     cin >> n;
  35.  
  36.     for (int i = 1; i <= n; i++)
  37.     {
  38.         time prom;
  39.         cin >> prom1 >> prom2;
  40.         prom.start = prom1;
  41.         prom.end = prom2;
  42.         times.push_back(prom);
  43.     }
  44.  
  45.     sort(times.begin(), times.end());
  46.  
  47.     prom1 = times[0].end;
  48.  
  49.     for (int i = 1; i < n; i++)
  50.     {
  51.         if (prom1 < times[i].start)
  52.         {
  53.             prom1 = times[i].end;
  54.             sc++;
  55.         }
  56.     }
  57.  
  58.     cout << sc;
  59.     _getch();
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment