Cod sursa(job #1412036)

Utilizator 4ONI2015oni2015 4ONI2015 Data 1 aprilie 2015 08:21:25
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <bits/stdc++.h>
#define punct pair<long long,long long>
#define x first
#define y second
#define mp make_pair

using namespace std;
punct p[100005];
int n, i, l, r;
double sol;
struct cmp
{
    bool operator()(punct a, punct b)
    {
        return a.y < b.y;
    }
};
double dist(punct a, punct b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
set<punct, cmp>s;
int main()
{
    freopen("cmap.in", "r", stdin);
    freopen("cmap.out", "w", stdout);
    scanf("%d", &n);
    for(i = 1; i <= n; i++)
        scanf("%lld%lld", &p[i].x, &p[i].y);
    sol=1<<30;
    sort(p + 1, p + n + 1);
    for(l = r = 1; r <= n; r++)
    {
        while(l <= r && p[r].x - p[l].x > sol)
        {
            s.erase(p[l]);
            l++;
        }
        for(auto it = s.lower_bound(mp(0ll, p[r].y - sol)); it != s.end() && it->y - p[r].y <= sol;it++)
            sol = min(sol, dist(*it, p[r]));
        s.insert(p[r]);
    }
    printf("%.9lf", sol);
    return 0;
}