Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL) INF;
- const int MAX = 50500;
- struct Point
- {
- int x, y;
- int ind;
- Point(int x, int y, int ind)
- {
- this->x = x;
- this->y = y;
- this->ind = ind;
- }
- Point(){}
- bool operator <(const Point& o)const
- {
- return y < o.y;
- }
- };
- bool cmpX(Point a, Point b)
- {
- return MP(a.x, a.y) < MP(b.x, b.y);
- }
- LL dist(Point a, Point b)
- {
- LL res = (a.x - b.x) * (LL)(a.x - b.x) + (a.y - b.y) * (LL)(a.y - b.y);
- return res;
- }
- Point X[MAX];
- Point T[MAX];
- VI V;
- int n;
- void merge(int L, int M, int R)
- {
- memcpy(T + L, X + L, sizeof(Point) * (R - L + 1));
- int ind1 = L, ind2 = M + 1;
- int ind = L;
- while(ind1 <= M || ind2 <= R)
- {
- if (ind1 > M)
- {
- X[ind++] = T[ind2++];
- continue;
- }
- if (ind2 > R)
- {
- X[ind++] = T[ind1++];
- continue;
- }
- if (T[ind1] < T[ind2])
- {
- X[ind++] = T[ind1++];
- }
- else
- {
- X[ind++] = T[ind2++];
- }
- }
- }
- pair<LL, PII> go(int L, int R)
- {
- if (R - L + 1 < 4)
- {
- pair<LL, PII> res = MP(LINF, MP(INF, INF));
- FOR (i, L, R + 1)
- {
- FOR (j, i+1, R + 1)
- {
- res = min(res, MP(dist(X[i], X[j]), MP(X[i].ind, X[j].ind)));
- }
- }
- sort(X+L, X+R+1);
- return res;
- }
- int M = (L + R) / 2;
- int midX = X[M].x;
- pair<LL, PII> res = min(go(L, M), go(M+1, R));
- merge(L, M, R);
- V.clear();
- FOR (i, L, R + 1)
- {
- if ((X[i].x - midX) * (LL)(X[i].x - midX) <= res.first)
- {
- RFOR(j, SZ(V), 0)
- {
- if ((X[i].y - X[V[j]].y) * (LL)(X[i].y - X[V[j]].y) > res.first) break;
- res = min(res, MP(dist(X[i], X[V[j]]), MP(X[i].ind, X[V[j]].ind)));
- }
- V.PB(i);
- }
- }
- return res;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- //ios::sync_with_stdio(false); cin.tie(0);
- scanf("%d", &n);
- FOR (i, 0, n)
- {
- int x, y;
- scanf("%d%d", &x, &y);
- X[i] = Point(x, y, i);
- }
- sort(X, X+n, cmpX);
- pair<LL, PII> res = go(0, n-1);
- if (res.second.first > res.second.second) swap(res.second.first, res.second.second);
- printf("%d %d %.6f\n", res.second.first, res.second.second, sqrt(res.first));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement