-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHiking Map.cpp
95 lines (77 loc) · 2.09 KB
/
Hiking Map.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
89
90
91
92
93
94
95
#include <bits/stdc++.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Point_2<K> Point;
typedef CGAL::Line_2<K> Line;
typedef CGAL::Triangle_2<K> Triangle;
using namespace std;
inline Point read_point() {
int x,y; cin >> x >> y;
return Point(x,y);
}
inline bool check(const vector<Point> &points, const Point &point) {
return !CGAL::right_turn(points[0],points[1],point) && !CGAL::right_turn(points[2],points[3],point) && !CGAL::right_turn(points[4],points[5],point);
}
void solve() {
int n,m;
cin >> m >> n;
vector<Point> points = vector<Point>(m);
for(int i = 0; i < m;i++) {
points[i] = read_point();
}
vector<vector<Point>> triangles = vector<vector<Point>>(n,vector<Point>(0));
for(int i = 0; i < n; i++) {
for(int j = 0; j < 6; j++) {
int x,y;
cin >> x >> y;
triangles[i].push_back(Point(x,y));
}
for(int j = 0; j < 6;j+=2) {
if(CGAL::right_turn(triangles[i][j],triangles[i][j+1],triangles[i][(j+2) % 6])) std::swap(triangles[i][j],triangles[i][j+1]);
}
}
vector<vector<bool>> contains(n,vector<bool>(m-1,false));
for(int i = 0; i < n;i++) {
vector<bool> inside(m,false);
for(int j = 0; j < m;j++) {
if(check(triangles[i],points[j]))
inside[j] = true;
}
for(int j = 0; j < m-1;j++) {
if(inside[j] && inside[j+1]) contains[i][j] = true;
}
}
int best = INT_MAX;
int start = -1;
int end = 0;
int counter = 0;
vector<int> mask(m-1,0);
while(start != n-1) {
start++;
for(int j = 0; j < m-1;j++) {
if(contains[start][j]) {
if(mask[j] == 0) counter++;
mask[j]++;
}
}
while(counter == m-1) {
best = min(best,start-end+1);
for(int j = 0; j < m-1;j++) {
if(contains[end][j]) {
mask[j]--;
if(mask[j] == 0) counter--;
}
}
end++;
}
}
cout << best << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
}