Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <math.h>
- #include <algorithm>
- #include <assert.h>
- #include <stack>
- using namespace std;
- const int MAXN = 100005;
- struct Vec {
- long long x, y;
- int id;
- explicit Vec(long long _x = 0, long long _y = 0) {
- x = _x;
- y = _y;
- }
- inline void scan() {
- long long a, b;
- //scanf("%lli %lli", &a, &b);
- cin >> a >> b;
- x = a + 1000;
- y = b + 1000;
- }
- void print() {
- cout << x << " " << y << "\n";
- }
- inline long long len2() {
- return x * x + y * y;
- }
- long long operator *(Vec const &a) const {
- return x * a.x + y * a.y;
- }
- Vec operator +(Vec &a) {
- return Vec(x + a.x, y + a.y);
- }
- inline Vec operator -(Vec &a) {
- return Vec(x - a.x, y - a.y);
- }
- };
- //vector<Points>
- vector<Vec> v[400][400];
- int main() {
- std::ios::sync_with_stdio(false);
- ios_base::sync_with_stdio(false);
- //freopen("zzz.in", "r", stdin);
- //freopen("zzz.out", "w", stdout);
- int n, m;
- cin >> n >> m;
- //int N = (int)sqrt(n) + 1;
- int N = 320;
- //cout << N << "\n";
- for (int i = 0; i < n; i++) {
- Vec point;
- point.scan();
- point.id = i;
- int num_x = point.x / N;
- int num_y = point.y / N;
- v[num_x][num_y].push_back(point);
- //cout << num_x << " " << num_y << "\n";
- }
- for (int i = 0; i < m; i++) {
- Vec point;
- point.scan();
- int num_x = point.x / N;
- int num_y = point.y / N;
- long long min_dist = 1e9;
- int best_id = -1;
- for (int j = max(0, num_x); j <= min(399, num_x + 1); j++)
- for (int k = max(0, num_y); k <= min(399, num_y + 1); k++)
- for (int q = 0; q < (int)v[j][k].size(); q++)
- if ((point - v[j][k][q]).len2() < min_dist) {
- min_dist = (point - v[j][k][q]).len2();
- best_id = v[j][k][q].id;
- }
- assert(best_id != -1);
- cout << best_id + 1 << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement