-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path858-berry_picking.cpp
More file actions
48 lines (37 loc) · 975 Bytes
/
858-berry_picking.cpp
File metadata and controls
48 lines (37 loc) · 975 Bytes
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
#include <bits/stdc++.h>
using namespace std;
using pii = pair<double, double>;
#define x first
#define y second
int main() {
int T;
cin >> T;
while (T--) {
int N;
double threshold, x0;
cin >> N;
vector<pii> points(N);
for (auto& p : points) cin >> p.x >> p.y;
cin >> threshold >> x0;
vector<double> ys;
for (int i = 0; i < N; i++) {
pii p = points[i];
pii q = points[(i + 1) % N];
if (p.x == q.x) continue;
if (p.x > q.x) swap(p, q);
if (x0 < p.x) continue;
if (q.x < x0) continue;
const double slope = (p.y - q.y) / (p.x - q.x);
const double dx = x0 - p.x;
ys.emplace_back(p.y + slope * dx);
}
sort(ys.begin(), ys.end());
double total = 0;
for (int i = 0; i < (int)ys.size() - 1; i += 2) {
const double y0 = ys[i];
const double y1 = ys[i + 1];
total += fabs(y1 - y0);
}
cout << (total > threshold ? "YES" : "NO") << endl;
}
}