Cod sursa(job #1623724)

Utilizator robertstrecheStreche Robert robertstreche Data 1 martie 2016 21:18:04
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define NMAX 100005
#define INF 1000000000000000000

using namespace std;

struct punct{
  int x,y;
}v[NMAX];

inline bool comp(punct p1,punct p2){
  return p1.x+p1.y<p2.x+p2.y;
}

inline long long min(long long a,long long b){
  if (a<=b)return a;
  return b;
}

inline long long dist(punct a,punct b){
  return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int main()
{
    freopen("cmap.in","r",stdin);
    freopen("cmap.out","w",stdout);

    int n;long long sol=INF;

    scanf("%d\n",&n);
    for (int i=1;i<=n;i++)scanf("%d %d\n",&v[i].x,&v[i].y);

    sort(v+1,v+n+1,comp);
    for (int i=1;i<=n;i++)
    for (int j=i+1;j<=i+7 && j<=n;j++){
        sol=min(sol,dist(v[i],v[j]));
    }
    printf("%f",sqrt((long long)sol));

    fclose(stdin);
    fclose(stdout);
}