-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.cpp
81 lines (67 loc) · 1.53 KB
/
point.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
};
long long sq(point &a, point &b, point &c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
}
bool border(point q, pair<point, point> p) {
point p1 = p.first;
point p2 = p.second;
return sq(p1, p2, q) == 0;
}
int get(point q, pair<point, point> p) {
point p1 = p.first;
point p2 = p.second;
int ans = 0;
if (p1.y == p2.y) {
ans = 0;
}
else if (q.y == max(p1.y, p2.y) && q.x < min(p1.x, p2.x)) {
ans = 1;
}
else if (q.y == min(p1.y, p2.y)) {
ans = 0;
}
else if (p1.y > p2.y) {
swap(p1, p2);
}
if (q.y <= p1.y || q.y > p2.y) {
ans = 0;
}
else if (sq(p1, p2, q) > 0) {
ans = 1;
}
return ans;
}
int main() {
int n;
cin >> n;
vector<point> points(n);
point q;
cin >> q.x >> q.y;
for (int i = 0; i < n; ++i) {
cin >> points[i].x >> points[i].y;
}
vector<pair<point, point>> segments(n);
for (int i = 0; i < n; ++i) {
segments[i] = {points[i], points[(i + 1)%n]};
}
for (auto segment : segments) {
if (border(q, segment)) {
cout << "YES";
return 0;
}
}
int cnt = 0;
for (auto segment : segments) {
cnt += get(q, segment);
}
if (cnt & 1) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}