Cod sursa(job #1637719)

Utilizator Burbon13Burbon13 Burbon13 Data 7 martie 2016 18:54:33
Problema Cele mai apropiate puncte din plan Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>
#include <algorithm>
#define x first
#define y second

using namespace std;

const int nmx = 100002;

int n;
double dmin;
pair <double,double> v[nmx];

void citire(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%lf %lf", &v[i].x, &v[i].y);
}

double dist(pair <double,double> p1, pair <double,double> p2){
    return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y);
}

int main(){
    freopen("cmap.in", "r", stdin);
    freopen("cmap.out", "w", stdout);
    citire();
    sort(v+1,v+n+1);
    dmin = dist(v[1],v[2]);
    for(int i = 3; i <= n; ++i){
        int j = i - 1;
        while(v[i].x-v[j].x < dmin && j >= 1){
            if(dmin > dist(v[i],v[j]))
                dmin = dist(v[i],v[j]);
            -- j;
        }
    }
    printf("%f\n", sqrt(dmin));
    return 0;
}