Cod sursa(job #2919970)

Utilizator Tiberiu02Tiberiu Musat Tiberiu02 Data 21 august 2022 12:47:42
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>
#include <math.h>
#include <stdlib.h>

#define x first
#define y second

using namespace std;

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

pair<double,double> v[1<<17];

double D(int a, int b) {
    return sqrt(pow((v[a].x-v[b].x),2) + pow((v[a].y-v[b].y),2));
}

int n;
double t;

int main() {
    double aplha = (rand() % 1000) * 8e-3 * atan(1);
    double s,c;
    s = sin(alpha), c = cos(alpha);
    f>>n;
    for(int i=1; i<=n; ++i) {
        double x, y;
        f >> x >> y;
        v[i].x = c * x + s * y;
        v[i].y = -s * x + c * y;
    }
    sort(v+1,v+n+1);
    t=1000000000;
    for(int i=1; i<=n; ++i)
        for(int j=i+1; j<=n; ++j) {
            if(v[j].x-v[i].x>t) break;
            t=min(t,D(i,j));
        }
    g<<fixed<<setprecision(6)<<t;
    return 0;
}