Cod sursa(job #1295872)

Utilizator radu_uniculeu sunt radu radu_unicul Data 20 decembrie 2014 12:51:39
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.82 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 pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int nmax = 100005;
const double inf = 1000000000000.0;

long long n, i, b, l, r;
double best, a;

struct point
{
    long long x, y;
};
point p[nmax];

struct cmps
{
    bool operator () (point a, point b) const
    {
        if(a.y == b.y) return a.x < b.x;
        return a.y < b.y;
    }
};

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

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

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

int main()
{
    ifstream fin("cmap.in");
    ofstream fout("cmap.out");

    fin >> n;

    for(i = 1; i <= n; i++)
        fin >> p[i].x >> p[i].y;

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

    s.insert(p[1]);
    best = inf;
    l = 1;

    for(r = 2; r <= n; r++)
    {
        b = (long long)(best + 1);

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

        point aux;
        aux.x = p[r].x;
        aux.y = p[r].y - b;
        it = s.lower_bound(aux);
        while(it != s.end() && it->y <= p[r].y + b)
        {
            best = min(best, dist(*it, p[r]));
            it++;
        }

        s.insert(p[r]);
    }

    fout << fixed << setprecision(7) << best;

    return 0;
}