Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9. vector<vector<int> >a(n, vector<int>(2));
  10. for (int i = 0; i < n; i++)
  11. cin >> a[i][0] >> a[i][1];
  12. for(int i = 0; i < n; i++)
  13. for(int x = 0; x < n; x++)
  14. {
  15. if (a[i][0] <= a[x][0] && a[i][1] >= a[x][1] && i != x)
  16. { // один отрезок прннадлежит другому
  17. a[x][0] = a[a.size() - 1][0];
  18. a[x][1] = a[a.size() - 1][1];
  19. a.pop_back();
  20. }
  21. else if (a[i][0] < a[x][0] && a[i][1] < a[x][1])
  22. {// отрезок пересекает другой
  23. a[i][1] = a[x][1];
  24. a[x][0] = a[a.size() - 1][0];
  25. a[x][1] = a[a.size() - 1][1];
  26. a.pop_back();
  27. }
  28. }
  29. cout << a.size() << endl;
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement