Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- struct rect{
- int x1;
- int y1;
- int x2;
- int y2;
- rect() : x1(0), y1(0), x2(0), y2(0){}
- rect(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2){}
- };
- rect r[1501];
- rect a;
- rect rect_intersection(rect a1, rect a2) {
- int X1 = max(a1.x1, a2.x1);
- int Y1 = max(a1.y1, a2.y1);
- int X2 = min(a1.x2, a2.x2);
- int Y2 = min(a1.y2, a2.y2);
- //cout << a1.x2 << " ";
- if (X2 < X1 || Y2 < Y1) {
- cout << -1;
- exit(0);
- }
- return rect(X1, Y1, X2, Y2);
- }
- int main()
- {
- freopen("rect.in", "r", stdin);
- freopen("rect.out", "w", stdout);
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> r[i].x1 >> r[i].y1 >> r[i].x2 >> r[i].y2;
- }
- a = r[0];
- //rect a = rect_intersection(r[0], r[1]);
- for (int i = 1; i < n; i++) {
- a = rect_intersection(a, r[i]);
- }
- cout << a.x1 << " " << a.y1 << " " << a.x2 << " " << a.y2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement