View difference between Paste ID: nTRRyU5x and h9PgTeDu
SHOW: | | - or go back to the newest paste.
1
#include <bits/stdc++.h>
2
#define all(x) (x).begin(),(x).end()
3
4
using namespace std;
5
using ll = long long;
6
7
struct pt {
8
    int x, y, i;
9
    bool operator < (const pt& o) {
10
        if (x != o.x) return x < o.x;
11
        return y < o.y;
12
    }
13
};
14
15
ll answer = 1e18;
16
int ind1 = -1, ind2 = -1;
17
const int MSIZE = 50505;
18
pt buff[MSIZE];
19
20
ll Dist(const pt& a, const pt& b) {
21
    return (a.x - b.x) * 1ll * (a.x - b.x) + (a.y - b.y) * 1ll * (a.y - b.y);
22
}
23
24
void DC(int tl, int tr, vector<pt>& arr) {
25
    if (tl + 1 < tr) {
26
        int tm = (tl + tr) / 2;
27
        DC(tl, tm, arr);
28
        DC(tm, tr, arr);
29
        int itr = 0;
30
        int xmid = arr[tm].x;
31
        for (int i = tl; i < tr; i++) {
32
            if ((xmid - arr[i].x) * 1ll * (xmid - arr[i].x) <= answer) {
33
                buff[itr++] = arr[i];
34
            }
35
        }
36
        sort(buff, buff + itr, [&] (const pt& a, const pt& b) {
37
            return a.y < b.y;
38
        });
39
        for (int i = 0; i < itr; i++) {
40
            for (int j = 1; j <= 8 && i + j < itr; j++) {
41
                if (answer > Dist(buff[i], buff[i + j])) {
42
                    answer = Dist(buff[i], buff[i + j]);
43
                    ind1 = buff[i].i;
44
                    ind2 = buff[i + j].i;
45
                }
46
            }
47
        }
48
    }
49
}
50
51
int main() {
52
    ios_base::sync_with_stdio(false);
53
    cin.tie(nullptr);
54
    cout.tie(nullptr);
55
    int n;
56
    cin >> n;
57
    vector<pt> arr(n);
58
    for (int i = 0; i < n; i++) {
59
        int x, y;
60
        cin >> x >> y;
61
        arr[i] = pt{x, y, i};
62
    }
63
    sort(all(arr));
64
    DC(0, n, arr);
65
    if (ind1 > ind2) swap(ind1, ind2);
66
    cout << ind1 << ' ' << ind2 << ' ';
67
    cout << fixed << setprecision(6) << sqrtl((long double) (answer)) << '\n';
68
}