-
Notifications
You must be signed in to change notification settings - Fork 185
/
pointinpolygon.cc
43 lines (40 loc) · 1.07 KB
/
pointinpolygon.cc
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
// https://open.kattis.com/problems/pointinpolygon
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
P(int x = 0, int y = 0) : x(x), y(y) {}
P operator-(P p) { return P(x - p.x, y - p.y); }
int operator*(P p) { return x * p.x + y * p.y; }
int operator^(P p) { return x * p.y - y * p.x; }
friend ostream &operator<<(ostream &os, P p) {
return os << '(' << p.x << ',' << p.y << ')';
}
};
int main() {
cin.tie(0), ios::sync_with_stdio(0);
while (1) {
int n, m, x, y;
cin >> n;
if (!n) break;
vector<P> ps(n);
for (int i = 0; i < n; i++) cin >> x >> y, ps[i] = P(x, y);
cin >> m;
while (m--) {
cin >> x >> y;
P a(x, y);
string ans = "";
bool c = 0;
for (int i = 0; i < n; i++) {
P p = ps[i], q = ps[(i + 1) % n];
if (((p - a) ^ (q - a)) == 0 && ((p - a) * (q - a) <= 0)) {
ans = "on";
break;
}
c ^= ((a.y < p.y) - (a.y < q.y)) * ((p - a) ^ (q - a)) > 0;
}
if (ans.empty()) ans = c ? "in" : "out";
cout << ans << '\n';
}
}
}