Cod sursa(job #3236209)

Utilizator SerbanCaroleSerban Carole SerbanCarole Data 26 iunie 2024 16:19:53
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2 kb
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
class InParser {
    vector<char> str;
    int ptr;
    ifstream fin;
    char getChar() {
        if (ptr == int(str.size())) {
            fin.read(str.data(), str.size());
            ptr = 0;
        }
        return str[ptr++];
    }
    template<class T>
    T getInt() {
        char chr = getChar();
        while (!isdigit(chr) && chr != '-')
            chr = getChar();
        int sgn = +1;
        if (chr == '-') {
            sgn = -1;
            chr = getChar();
        }
        T num = 0;
        while (isdigit(chr)) {
            num = num * 10 + chr - '0';
            chr = getChar();
        }
        return sgn * num;
    }
public:
    InParser(const char* name) : str(1e5), ptr(str.size()), fin(name) { }
    ~InParser() { fin.close(); }

    template<class T>
    friend InParser& operator>>(InParser& in, T& num) {
        num = in.getInt<T>();
        return in;
    }
};
InParser cin("cmap.in");
ofstream cout("cmap.out");
// e infoarena deci probabil se ia 100 cu asta
int n;
struct point{int x,y;};
point p[100001];
double formula(point unu, point doi)
{
    return sqrtl(1LL*(unu.x-doi.x)*(unu.x-doi.x)+1LL*(unu.y-doi.y)*(unu.y-doi.y));
}
signed main()
{
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)
    {
        int asta , ala;
        cin >> asta >> ala;
        p[i] = {asta,ala};
    }
    int bulan = 10000;
    sort(p+1,p+1+n,[](point unu,point doi){
         if(unu.x==doi.x) return unu.y<doi.y;
         else return unu.x<doi.x;});
    double dist = formula(p[1],p[2]);
    for(int i = 3 ; i <= n ; ++i)
    {
        for(int j = i-1 ; j >= 1 ; --j)
        {
            int d = (int)dist;
            if(p[i].x-p[j].x > d) break;
            dist = min(dist,formula(p[i],p[j]));
        }
    }
   // if(dist > (double)bulan) while(1){}
    cout << fixed << setprecision(6) << dist ;
    return 0;
}