Cod sursa(job #2834895)

Utilizator BalasaRaduBalasa Radu BalasaRadu Data 17 ianuarie 2022 20:22:07
Problema Cele mai apropiate puncte din plan Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("cmap.in");
ofstream fout("cmap.out");

const int dim=100009;

struct punct{
    int x,y;
    bool operator <(const punct &other) const
    {
        if(x==other.x){
            return y<other.y;
        }
        return x<other.x;
    }
};

set<punct>s;

punct v[dim];

bool cmp(punct a, punct b){
    if(a.x==b.x){
        return a.y<b.y;
    }
    return a.x<b.x;
}

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

signed main(){
    int n;
        fin>>n;
    for(int i=1;i<=n;i++){
        fin>>v[i].x>>v[i].y;
    }
    sort(v+1,v+n+1);
    double hmax=dist(v[1],v[2]);
    for(int i=1;i<=n;i++){
        auto it=s.begin();
        while(dist(v[i],*it)>hmax&&it!=s.end()){
            s.erase(*it);
            it=s.begin();
        }
        for(auto other:s){
            hmax=min(hmax,dist(other,v[i]));
        }
        s.insert(v[i]);
    }
        fout<<fixed<<setprecision(8)<<hmax;
}