Cod sursa(job #1623743)

Utilizator robertstrecheStreche Robert robertstreche Data 1 martie 2016 21:24:07
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cmath>
#include <fstream>
#include <iomanip>
#include <algorithm>

#define NMAX 100005
#define INF 1000000000000000000

using namespace std;

struct punct{
  long long 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()
{
    ifstream f("cmap.in");
    ofstream g("cmap.out");

    int n;long long sol=INF;

    f>>n;
    for (int i=1;i<=n;i++)f>>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]));
    }
    g<<fixed<<setprecision(6)<<sqrt((long long)sol);

    fclose(stdin);
    fclose(stdout);
}