Cod sursa(job #902011)

Utilizator alex45meOlaru Alex alex45me Data 1 martie 2013 12:33:09
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;


FILE *f=fopen("cmap.in","r");
FILE *g=fopen("cmap.out","w");

int i,j,n;
double mn;

struct vect
{
    int x,y;
}v[100001];


bool cmp(vect i,vect j)
{
    if (i.x<j.x) return 1;
    else if (i.x==j.x && i.y<j.y) return 1;
    else return 0;
}


double dst(vect i, vect j)
{
     return sqrt((i.x-j.x)*(i.x-j.x) + (i.y-j.y)*(i.y-j.y));
}




int main()
{
      fscanf(f,"%d",&n);
      for (i=1;i<=n;i++)
       fscanf(f,"%d %d",&v[i].x,&v[i].y);
      sort(v+1,v+n+1,cmp);
      mn=dst(v[1],v[n]);
      for (i=1;i<=n;i++)
        for (j=i+1;j<=i+7;j++)
          if (dst(v[i],v[j])<mn) { mn=dst(v[i],v[j]);}

      fprintf(g,"%.6lf",mn);

     fclose(g); fclose(f);
	return 0;
}