-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoints inside convex polygon in logn.cpp
89 lines (49 loc) · 1.17 KB
/
Points inside convex polygon in logn.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
82
83
84
85
86
87
88
#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
struct point
{
i64 x, y;
point() {}
point(int x, int y) : x(x), y(y) {}
} a[100005];
i64 orientation(point a, point b, point c) // triangle area
{
return a.x*(b.y - c.y) + b.x*(c.y - a.y) + c.x*(a.y - b.y);
}
bool binarySearch(point qp, int n)
{
int lo = 1, hi = n-1, mid;
while((hi-lo) > 1)
{
mid = (hi+lo)/2;
if(orientation(a[0], a[mid], qp) < 0) hi = mid;
else lo = mid;
}
if(orientation(a[0], a[lo], qp) < 0) return false;
if(orientation(a[lo], a[hi], qp) < 0) return false;
if(orientation(a[hi], a[0], qp) < 0) return false;
return true;
}
int main()
{
int test, cs = 0;
cin>>test;
while(test--)
{
int n;
scanf("%d", &n);
for(int i = 0; i<n; i++) scanf("%lld %lld", &a[i].x, &a[i].y);
int q;
cin>>q;
printf("Case %d:\n", ++cs);
while(q--)
{
point tmp;
scanf("%lld %lld", &tmp.x, &tmp.y);
if(binarySearch(tmp, n)==true) puts("y");
else puts("n");
}
}
return 0;
}