Cod sursa(job #1820412)

Utilizator Y0da1NUME JMECHER Y0da1 Data 1 decembrie 2016 18:05:43
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <math.h>
#define i64 unsigned long long
using namespace std;
class punct{
public:
    i64 x;
    i64 y;
    bool operator <(const punct p2) const
    {
        return x < p2.x;
    }
};
int n, i, j;
punct p[100005];
long long dist(punct p1, punct p2)
{
    return /*sqrt*/( (p1.x - p2.x)*(p1.x - p2.x) +
                 (p1.y - p2.y)*(p1.y - p2.y)  );
}
int main()
{
    ifstream in("cmap.in");
    ofstream out("cmap.out");
    in>>n;
    for(i=0;i<n;i++)
        in>>p[i].x>>p[i].y;
    sort(p,p+n);
    long long sol=4e18;
    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]);
    out<<fixed<<setprecision(6)<<sqrt((double)sol)<<"\n";
    in.close();
    out.close();
    return 0;
}