Cod sursa(job #1817537)

Utilizator jordan1998Jordan jordan1998 Data 27 noiembrie 2016 23:39:33
Problema Cele mai apropiate puncte din plan Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.18 kb
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#define INF 2000000000
#define MAXN 100010
using namespace std;
FILE*f=freopen("cmap.in","r",stdin);
char buff[200000];
int pos=0;
typedef struct{
int x,y;
}punct;
punct p[MAXN];
int i,j,n;
long long sol;
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));
}
bool cmp(punct a,punct b)
{
    return a.x<b.x;
}
inline void read(int &nr)
{
    while(buff[pos] < '0' || buff[pos] > '9') if(++pos == 200000) fread(buff,  1,200000, stdin), pos = 0;
    nr = 0;
    while('0' <= buff[pos] && buff[pos] <= '9')
    {
        nr = (nr<<1)+(nr<<3)+ buff[pos] - '0';
        if(++pos == 200000) fread(buff, 1,200000, stdin), pos = 0;
    }
}
int main()
{
    ifstream fi("cmap.in");
    ofstream fo("cmap.out");
   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]);
    fo<<setprecision(6)<<fixed;
    fo<<sqrt((double)sol)<<"\n";
    return 0;
}