-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
155 lines (115 loc) · 3.78 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <cmath>
#include <iostream>
#include <limits>
#include <queue>
#include <vector>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>
#include <CGAL/Triangulation_vertex_base_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<int, K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K, Tds> Delaunay;
typedef K::Point_2 Point;
void testcase() {
int numDementors, numFugitives;
long d;
std::cin >> numDementors >> numFugitives >> d;
std::vector<Point> dementors = std::vector<Point>(numDementors);
for (int i = 0; i < numDementors; i++) {
long x, y;
std::cin >> x >> y;
dementors[i] = {x, y};
}
Delaunay t;
t.insert(dementors.begin(), dementors.end());
// 0 corresponds to infinite face
int numFaces = 1;
for (auto f = t.finite_faces_begin(); f != t.finite_faces_end(); f++) {
f->info() = numFaces;
numFaces++;
}
std::vector<std::vector<std::pair<int, K::FT>>> adjList =
std::vector<std::vector<std::pair<int, K::FT>>>(numFaces);
std::vector<K::FT> faceRadii = std::vector<K::FT>(numFaces);
for (auto f = t.finite_faces_begin(); f != t.finite_faces_end(); f++) {
int currIdx = f->info();
for (int i = 0; i < 3; i++) {
auto neighboringFace = f->neighbor(i);
int neighborIdx = 0;
if (!t.is_infinite(neighboringFace)) {
neighborIdx = neighboringFace->info();
}
Point v1 = f->vertex((i + 1) % 3)->point();
Point v2 = f->vertex((i + 2) % 3)->point();
K::FT dist = CGAL::squared_distance(v1, v2);
adjList[currIdx].push_back({neighborIdx, dist});
if (neighborIdx == 0) {
adjList[neighborIdx].push_back({currIdx, dist});
}
}
faceRadii[currIdx] = CGAL::squared_radius(
f->vertex(0)->point(), f->vertex(1)->point(), f->vertex(2)->point());
}
// Now do prioqueue approach
auto comparator = [](std::pair<int, K::FT> a, std::pair<int, K::FT> b) {
return a.second < b.second;
};
std::priority_queue<std::pair<int, K::FT>, std::vector<std::pair<int, K::FT>>,
decltype(comparator)>
prioQueue(comparator);
K::FT maximum = K::FT(std::numeric_limits<long>::max());
prioQueue.push({0, 4 * (maximum + maximum) * (maximum + maximum)});
for (int i = 0; i < numFaces; i++) {
prioQueue.push({i, faceRadii[i]});
}
std::vector<K::FT> faceMax = std::vector<K::FT>(numFaces, -1);
while (!prioQueue.empty()) {
auto current = prioQueue.top();
int idx = current.first;
K::FT dist = current.second;
prioQueue.pop();
if (faceMax[idx] != -1) {
continue;
}
faceMax[idx] = dist;
for (auto neighbor : adjList[idx]) {
if (faceMax[neighbor.first] == -1) {
prioQueue.push({neighbor.first, std::min(dist, neighbor.second)});
}
}
}
for (int i = 0; i < numFugitives; i++) {
long x, y, s;
std::cin >> x >> y >> s;
Point fugitive = {x, y};
Point nearestPoint = t.nearest_vertex(fugitive)->point();
if (CGAL::squared_distance(fugitive, nearestPoint) <
K::FT(s + d) * K::FT(s + d)) {
std::cout << "n";
continue;
}
auto face = t.locate(fugitive);
int faceIdx = 0;
if (!t.is_infinite(face)) {
faceIdx = face->info();
}
if (faceMax[faceIdx] >=
K::FT(4) * K::FT(K::FT(s) + K::FT(d)) * K::FT(K::FT(s) + K::FT(d))) {
std::cout << "y";
} else {
std::cout << "n";
}
}
std::cout << "\n";
}
int main() {
std::ios_base::sync_with_stdio(false);
int t;
std::cin >> t;
for (int i = 0; i < t; i++) {
testcase();
}
}