-
Notifications
You must be signed in to change notification settings - Fork 1
/
Points211.cpp
65 lines (65 loc) · 1.62 KB
/
Points211.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
#include <iostream>
using namespace std;
class Point {
public:
int x, y;
Point(int a, int b);
Point();
};
Point::Point(int a, int b) {
x = a;
y = b;
}
Point::Point() {
x = y = 0;
}
int determinant(Point p1, Point p2) {
return (p1.x*p2.y - p2.x*p1.y);
}
int main() {
int p;
Point set1[100000];
while (cin >> p) {
for (int i = 0; i < p; i++) {
cin >> set1[i].x >> set1[i].y;
}
int r;
cin >> r;
for (int h = 0; h < r; h++) {
int x, y;
cin >> x >> y;
Point point(x,y);
bool flag = false;
for (int i = 0; i < p && !flag; i++) {
for (int j = i+1; j < p && !flag; j++) {
for (int k = j+1; k < p && !flag; k++) {
Point p1 = set1[i];
Point p2 = set1[j];
Point p3 = set1[k];
//(x1y2 - x2y1) + (x2y3 - x3y2) + (x3y1 - x1y3) > 0 anticlockwise turning condition
//Use Determinant
int check1 = determinant(p1, p2) + determinant(p2, point) + determinant(point, p1);
int check2 = determinant(p3, p2) + determinant(p2, point) + determinant(point, p3);
if (check1*check2 <= 0) {
check1 = determinant(p2, p1) + determinant(p1, point) + determinant(point, p2);
check2 = determinant(p3, p1) + determinant(p1, point) + determinant(point, p3);
if (check1*check2 <= 0) {
check1 = determinant(p1, p3) + determinant(p3, point) + determinant(point, p1);
check2 = determinant(p2, p3) + determinant(p3, point) + determinant(point, p2);
if (check1*check2 <= 0) {
flag = true;
break;
}
}
}
}
}
}
if (flag)
cout << "inside" << endl;
else
cout << "outside" << endl;
}
}
return 0;
}