/
kdtree_nns.test.cpp
61 lines (52 loc) · 1.17 KB
/
kdtree_nns.test.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
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#include "my_template.hpp"
#include "random/base.hpp"
#include "ds/kdtree/kdtree.hpp"
void test_random_points_nns_is_fast() {
ll N = 100'000, Q = 100'000;
vc<int> X(N), Y(N);
ll LIM = 1'000'000'000;
FOR(i, N) X[i] = RNG(0, LIM);
FOR(i, N) Y[i] = RNG(0, LIM);
KDTree<int> KDT(X, Y);
FOR(Q) {
ll x = RNG(0, LIM);
ll y = RNG(0, LIM);
KDT.nearest_neighbor_search<ll>(x, y);
}
}
void test_nns_is_correct() {
ll LIM = RNG(10, 1000);
ll N = RNG(1, 100);
ll Q = 1000;
vc<int> X(N), Y(N);
FOR(i, N) X[i] = RNG(0, LIM);
FOR(i, N) Y[i] = RNG(0, LIM);
KDTree<int> KDT(X, Y);
FOR(Q) {
ll x = RNG(0, LIM);
ll y = RNG(0, LIM);
ll min_d = 1'000'000'000;
auto dist = [&](int i) -> ll {
ll dx = X[i] - x, dy = Y[i] - y;
return dx * dx + dy * dy;
};
FOR(i, N) chmin(min_d, dist(i));
int k = KDT.nearest_neighbor_search<ll>(x, y);
assert(min_d == dist(k));
}
}
void test() {
test_random_points_nns_is_fast();
test_nns_is_correct();
}
void solve() {
int a, b;
cin >> a >> b;
cout << a + b << "\n";
}
signed main() {
test();
solve();
return 0;
}