Cod sursa(job #1817790)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 28 noiembrie 2016 14:50:13
Problema Cele mai apropiate puncte din plan Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
#include <cmath>
#include <cstdio>
#include <algorithm>
#define INF 2000000000
#define MAXN 100010

using namespace std;
struct punct{int x,y;}p[MAXN];
int i,j,n;
long long sol;
FILE *f=freopen("cmap.in","r",stdin);
FILE *g=freopen("cmap.out","w",stdout);
#define buff_size 1048576
char buff[buff_size];
int pos=0;

inline void read(int &nr)
{
    while(!isdigit(buff[pos])) if(++pos == buff_size) fread(buff,  1,buff_size, stdin), pos = 0;
    nr = 0;
    while(isdigit(buff[pos]))
    {
        nr = (nr<<1)+(nr<<3)+ buff[pos] - 48;
        if(++pos == buff_size) fread(buff, 1, buff_size, stdin), pos = 0;
    }
}


inline long long dist(punct a,punct b) {return (long long)((long long)(a.x-b.x)*(a.x-b.x)+(long long)(a.y-b.y)*(a.y-b.y));}
struct cmp{
inline bool operator ()(punct a,punct b){return a.x<b.x;}
};

int main()
{   fread(buff,  1,buff_size, stdin);
    read(n);
    for(i=0;i<n;i++)
    read(p[i].x),read(p[i].y);
    sort(p,p+n,cmp());
    sol=(1LL<<61);
    for(i=0;i<n;i++)
    for(j=i+1;j<=i+3 and j<n;j++)   if(dist(p[i],p[j])<sol) sol=dist(p[i],p[j]);
    printf("%.6f", sqrt((double)sol));
}