-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2192 - Point in Polygon.cpp
More file actions
59 lines (50 loc) · 1.37 KB
/
2192 - Point in Polygon.cpp
File metadata and controls
59 lines (50 loc) · 1.37 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct P {
ll x, y;
void read() { cin >> x >> y; }
P operator-(P p) { return P{x - p.x, y - p.y}; }
ll cross(P p) { return x * p.y - y * p.x; }
ll cross(P a, P b) { return (a - *this).cross(b - *this); }
};
void solve() {
int n, m;
cin >> n >> m;
vector<P> v(n);
for (auto &i : v) i.read();
auto intersect = [](P cur, P p1, P p2) {
return cur.cross(p1, p2) == 0 &&
(min(p1.x, p2.x) <= cur.x && max(p1.x, p2.x) >= cur.x) &&
(min(p1.y, p2.y) <= cur.y && max(p1.y, p2.y) >= cur.y);
};
while (m--) {
P cur;
cur.read();
int crossings = 0;
bool isBoundary = false;
for (int i = 0; !isBoundary && i < n; i++) {
auto p1 = v[i], p2 = v[(i + 1) % n];
if (p1.y > p2.y) swap(p1, p2);
if (intersect(cur, p1, p2)) {
isBoundary = true;
} else {
auto isTouch = cur.cross(p1, p2) >= 0;
auto isBetween = (p1.y < cur.y) && (p2.y >= cur.y);
if (isTouch && isBetween) crossings++;
}
}
if (!isBoundary)
cout << (crossings & 1 ? "INSIDE\n" : "OUTSIDE\n");
else
cout << "BOUNDARY\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}