Cod sursa(job #1410838)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 31 martie 2015 12:13:26
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.75 kb
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "cmap";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif

struct point {
    int x, y;

    point() {}

    point(int _x, int _y) {
        x = _x;
        y = _y;
    }

    bool operator<(const point &B) const {
        return x < B.x;
    }
};

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

const int NMAX = 100000 + 5;
const int INF = (1 << 29);

int N;
point P[NMAX];
set<point, cmp> S;
double sol;

double dist(point A, point B) {
    return sqrt((A.x - B.x) * 1LL * (A.x - B.x) + (A.y - B.y) * 1LL * (A.y - B.y));
}

int main() {
    int i, j;

#ifndef ONLINE_JUDGE
    freopen(inputFile.c_str(), "r", stdin);
    freopen(outputFile.c_str(), "w", stdout);
#endif

    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(i = j = 1; i <= N; i++) {
        while((j <= i) && (P[i].x - P[j].x > sol)) {
            S.erase(P[j]);
            j++;
        }

        auto it = S.lower_bound(point(0, P[i].y - sol - 1));

        for(; (it != S.end()) && (it->y - P[i].y <= sol); it++)
            sol = min(sol, dist(*it, P[i]));

        S.insert(P[i]);
    }

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

    return 0;
}