Cod sursa(job #1413532)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 1 aprilie 2015 22:14:41
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.57 kb
#include<cstdio>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<unordered_map>

#define ll long long
#define pb push_back
#define mp make_pair
#define point pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define x first
#define y second

using namespace std;

const int nmax = 100005;
const double inf = 1e10;

int n, i, l, r;
point p[nmax];
double sol;
ll best;

struct cmp
{
    bool operator () (const point &a, const point &b) const
    {
        return a.y < b.y;
    }
};

set<point, cmp> s;
set<point>::iterator it;

double dist(point a, point b)
{
    return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + 1.0 * (a.y - b.y) * (a.y - b.y));
}

int main()
{
    freopen("cmap.in", "r", stdin);
    freopen("cmap.out", "w", stdout);

    scanf("%d", &n);

    for(i = 1; i <= n; i++)
        scanf("%d%d", &p[i].x, &p[i].y);

    sort(p + 1, p + n + 1);

    sol = inf;
    for(l = 1, r = 1; r <= n; r++)
    {
        best = (ll)sol + 1;

        while(l < r && p[l].x + best < p[r].x)
        {
            s.erase(p[l]);
            l++;
        }

        point aux = mp(0, p[r].y - best);
        for(it = s.lower_bound(aux); it != s.end() && it->y <= p[r].y + best; it++)
            sol = min(sol, dist(*it, p[r]));

        s.insert(p[r]);
    }

    printf("%.10f\n", sol);

    return 0;
}