Cod sursa(job #991383)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 30 august 2013 13:25:49
Problema Cele mai apropiate puncte din plan Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
FILE *f=fopen("cmap.in","r"),*g=fopen("cmap.out","w");
struct punct{long long  x,y;}v1[100005];
long long int k,l,m,n;
long long int dist(punct a, punct b){return (long long int)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
 
struct cmp
{
    bool operator()(const punct p1,const punct p2)const
    {
        if(p1.x<p2.x)return 1;
        if(p1.x==p2.x && p1.y<p2.y)return 1;
        return 0;
    }
};
 
int main()
{
    fscanf(f,"%lld",&n);
    int i,j;
    for(i=1;i<=n;i++)
        fscanf(f,"%lld %lld",&v1[i].x,&v1[i].y);
    sort(v1+1,v1+n+1,cmp());
    long long int rez=1000000000000000000;
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
            if(dist(v1[i],v1[j])<rez)
                rez=dist(v1[i],v1[j]);
    fprintf(g,"%lf",(double)sqrt(rez));
    return 0;
}