Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. struct rect{
  7. int x1;
  8. int y1;
  9. int x2;
  10. int y2;
  11. rect() : x1(0), y1(0), x2(0), y2(0){}
  12. rect(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2){}
  13. };
  14. rect r[1501];
  15. rect a;
  16. rect rect_intersection(rect a1, rect a2) {
  17. int X1 = max(a1.x1, a2.x1);
  18. int Y1 = max(a1.y1, a2.y1);
  19. int X2 = min(a1.x2, a2.x2);
  20. int Y2 = min(a1.y2, a2.y2);
  21. //cout << a1.x2 << " ";
  22. if (X2 < X1 || Y2 < Y1) {
  23. cout << -1;
  24. exit(0);
  25. }
  26. return rect(X1, Y1, X2, Y2);
  27. }
  28. int main()
  29. {
  30. freopen("rect.in", "r", stdin);
  31. freopen("rect.out", "w", stdout);
  32. int n;
  33. cin >> n;
  34. for (int i = 0; i < n; i++) {
  35. cin >> r[i].x1 >> r[i].y1 >> r[i].x2 >> r[i].y2;
  36. }
  37. a = r[0];
  38. //rect a = rect_intersection(r[0], r[1]);
  39. for (int i = 1; i < n; i++) {
  40. a = rect_intersection(a, r[i]);
  41. }
  42. cout << a.x1 << " " << a.y1 << " " << a.x2 << " " << a.y2;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement