Cod sursa(job #2199705)

Utilizator Anastasia11Susciuc Anastasia Anastasia11 Data 28 aprilie 2018 19:32:02
Problema Cele mai apropiate puncte din plan Scor 25
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define Nmax  1000005

using namespace std;

ifstream f("cmap.in");
ofstream g("cmap.out");

struct point{
int x, y;
}v[Nmax];

int n;
double ans;
double d;

bool cmp(point a, point b)
{
    return a.x<b.x;
}

double dist( point a, point b)
{
    return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}

int main()
{
    f >> n;
     for ( int i = 1 ; i <= n ; i ++ )
      f >> v[i].x >> v[i].y;
    sort(v+1, v+n+1, cmp);
    ans=dist(v[1],v[2]);
     for (int i = 1 ; i <= n ; i ++ )
      {
        for (int j = i-1 ; j >= 1 && v[i].x - v[j].x < ans ; j -- )
         {
            d = dist(v[j], v[i]);
            if (ans > d)
               ans = d;
        }
    }
    g << fixed << setprecision(6) << ans;


    return 0;
}