Cod sursa(job #2712335)

Utilizator CronosClausCarare Claudiu CronosClaus Data 25 februarie 2021 17:39:17
Problema Cele mai apropiate puncte din plan Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>
#define pp pair<int, int>
#define x first
#define y second

using namespace std;

const int mxn = 100 * 1000 + 10;


pair <int, int> punct[ mxn ];


int n;

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

inline int distX(pp a, pp b){
    return (a.x - b.x) * (a.x - b.x);
}

int main()
{
    ifstream cin("cmap.in");
    ofstream cout("cmap.out");
    cin>> n;
    for(int i = 0; i < n; i++){
        cin>>punct[ i ].x >> punct[ i ].y;
    }

    sort(punct, punct + n);

    int sol = INT_MAX;

    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n && distX(punct[ i ], punct[ j ]) <= sol; j++){
            sol = min(sol, dist(punct[ i ], punct[ j ]));
        }
    }

    cout<< setprecision( 6 ) << fixed << (double)sqrt(sol);

    return 0;
}