Cod sursa(job #1621476)

Utilizator alittlezzCazaciuc Valentin alittlezz Data 29 februarie 2016 19:20:00
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long unsigned
#define pb push_back
#define mp make_pair

pair <int, int> p[100005];

ll dist(pair <int, int> x, pair<int, int> y){
    ll d1,d2;
    d1 = (x.first-y.first)*(x.first-y.first);
    d2 = (x.second-y.second)*(x.second-y.second);
    return d1+d2;
}

int main(){
    int j,i,n,a,b;
    freopen("cmap.in", "r", stdin);
    freopen("cmap.out", "w", stdout);
    scanf("%d",&n);
    for(i = 1;i <= n;i++){
        scanf("%d %d",&a,&b);
        p[i].first = a;
        p[i].second = b;
    }
    sort(p+1, p+n+1);
    ll dmn = 8e18;
    for(i = 2;i <= n;i++){
        for(j = i-1;j >= 1;j--){
            if(p[i].first - p[i].first > d){
                break;
            }
            dmn = min(dmn, dist(p[i], p[j]));
        }
    }
    double ans = sqrt(dmn);
    printf("%.6f\n",ans);
    return 0;
}