-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
38 lines (37 loc) · 928 Bytes
/
B.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
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int W, H, x1, y1, x2, y2;
cin >> W >> H;
cin >> x1 >> y1 >> x2 >> y2;
int w, h;
cin >> w >> h;
if (w + x2 - x1 > W && h + y2 - y1 > H) {
cout << "-1\n";
continue;
}
int ans = 1e9;
if (-x1 + x2 + w <= W) {
if (x1 < w) {
ans = w-x1;
}
else ans = 0;
if (W-x2 < w){
ans = min(ans, x2 - W + w);
}
else ans = 0;
}
if (y2 - y1 + h <= H) {
if (y1 < h) {
ans = min(ans, h-y1);
}
else ans = 0;
if (H-y2 < h) ans = min(ans, y2 - H + h);
else ans = 0;
}
cout << ans << ".000000\n";
}
}