-
Notifications
You must be signed in to change notification settings - Fork 0
/
1665-decorate_the_wall.cpp
58 lines (46 loc) · 1.15 KB
/
1665-decorate_the_wall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
struct Rectangle {
int x1, y1, x2, y2;
bool intersects(const Rectangle& r) const {
if (r.x2 <= x1) return false;
if (x2 <= r.x1) return false;
if (r.y2 <= y1) return false;
if (y2 <= r.y1) return false;
return true;
}
};
void solve() {
int n, w, h;
cin >> n >> w >> h;
vector<Rectangle> rectangles(n);
for (auto& r : rectangles) cin >> r.x1 >> r.y1 >> r.x2 >> r.y2;
int w0, h0;
cin >> w0 >> h0;
set<int> xs{0, w - w0};
set<int> ys{0, h - h0};
for (const auto& r : rectangles) {
xs.emplace(r.x1 - w0);
xs.emplace(r.x2);
ys.emplace(r.y1 - h0);
ys.emplace(r.y2);
}
for (const auto y : ys) {
if (y < 0 || y + h0 > h) continue;
for (const auto x : xs) {
if (x < 0 || x + w0 > w) continue;
const Rectangle candidate{x, y, x + w0, y + h0};
if (!any_of(rectangles.begin(), rectangles.end(),
[&](const Rectangle& r) { return r.intersects(candidate); })) {
cout << x << " " << y << endl;
return;
}
}
}
cout << "Fail!" << endl;
}
int main() {
int t;
cin >> t;
while (t--) solve();
}