Cod sursa(job #2397194)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 4 aprilie 2019 11:33:21
Problema Cele mai apropiate puncte din plan Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>
#define ld long double
#define Nmax 100005
#define _point pair <ld,ld>
#define x first
#define y second

using namespace std;

ifstream f("cmap.in");
ofstream g("cmap.out");

inline ld sqr(const ld &x){

    return x*x;
}

inline ld get_dist(const _point &lsh, const _point &rsh){

    return sqrt(sqr(lsh.x-rsh.x)+sqr(lsh.y-rsh.y));
}

_point v[Nmax];
int N;

int main(){

    f>>N;

    for(int i=1;i<=N;i++)
        f>>v[i].x>>v[i].y;

    sort(v+1,v+N+1);

    ld dist=get_dist(v[1],v[2]);

    for(int j,i=1;i<=N;i++)
        for(j=i-1;j>0 and v[i].x-v[j].x<dist;j--){

            ld temp=get_dist(v[i],v[j]);
            if(temp<dist)
                dist=temp;
        }

    g<<fixed<<setprecision(6)<<dist;

    return 0;
}