-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1894-nonflying_weather.cpp
More file actions
68 lines (54 loc) · 1.81 KB
/
1894-nonflying_weather.cpp
File metadata and controls
68 lines (54 loc) · 1.81 KB
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
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Point {
int x, y;
Point operator-(const Point p) const { return {x - p.x, y - p.y}; }
Point operator+(const Point p) const { return {x + p.x, y + p.y}; }
ll cross(const Point p) const { return (ll)x * p.y - (ll)y * p.x; }
ll operator*(const Point p) const { return (ll)x * p.x + (ll)y * p.y; }
double dist(const Point p) const { return hypot(x - p.x, y - p.y); }
bool operator<(const Point p) const { return y < p.y || (y == p.y && x < p.x); }
double segment_dist(const Point p, const Point q) const {
const Point r = *this;
if ((q - p) * (r - p) <= 0) return p.dist(r);
if ((p - q) * (r - q) <= 0) return q.dist(r);
return fabs((q - p).cross(r - p)) / p.dist(q);
}
};
vector<Point> minkowski(vector<Point> P, vector<Point> Q) {
rotate(P.begin(), min_element(P.begin(), P.end()), P.end());
rotate(Q.begin(), min_element(Q.begin(), Q.end()), Q.end());
const int n = P.size();
const int m = Q.size();
vector<Point> res;
int i = 0, j = 0;
while (i < n || j < m) {
res.emplace_back(P[i % n] + Q[j % m]);
const ll cross = (P[(i + 1) % n] - P[i % n]).cross(Q[(j + 1) % m] - Q[j % m]);
i += cross >= 0;
j += cross <= 0;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
const Point origin{0, 0};
int n, m;
while (cin >> n >> m) {
vector<Point> P(n), Q(m);
for (auto& p : P) cin >> p.x >> p.y;
for (auto& p : Q) {
cin >> p.x >> p.y;
p.x = -p.x;
p.y = -p.y;
}
const vector<Point> R = minkowski(P, Q);
double dist = DBL_MAX;
for (size_t i = R.size() - 1, j = 0; j < R.size(); i = j++) {
dist = min(dist, origin.segment_dist(R[i], R[j]));
}
cout << fixed << setprecision(9) << max(dist - 60, 0.0) << endl;
}
}