Cod sursa(job #1520135)

Utilizator alittlezzCazaciuc Valentin alittlezz Data 8 noiembrie 2015 12:59:42
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 2.12 kb
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

//const int m = 1e9+7;
//const double e = 1e-6;

//long long lgPow(long long a, long long b);
//int binarySearch(int x, int n);
//void sieve(int n);
//inline int gcd(int a, int b);
double dist(pair<int, int> a, pair<int, int> b);


//const int N = 100;
//int st[N+5], dr[50], sp[50];
//bool ciur[N+5];
//int a[N+5];
//int d[N+5];
//int v[N+5];
//char m[N+5][N+5];
//map <int, int> m;
//bool a[26];
//char s[N+5];
//string s;

int main()
{
    int n,i,j;
    freopen("cmap.in", "r", stdin);
    freopen("cmap.out", "w", stdout);
    scanf("%d",&n);
    pair <int, int> ab[100005];
    for(i = 1;i <= n;i++){
        scanf("%d %d",&ab[i].first,&ab[i].second);
    }
    sort(ab+1,ab+n+1);
    double dd;
    double d = dist(ab[1], ab[2]);
    for(i = 3;i <= n;i++){
        for(j = i-1;j >= 1;j--){
            if(ab[i].first - ab[j].first > d){
                break;
            }
            dd = dist(ab[i], ab[j]);
            d = min(d,dd);
        }
    }
    d = sqrt(d);
    printf("%.6f",d);
    return 0;
}

double dist(pair<int, int> a, pair<int, int> b){
    return (a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second);
}

//long long lgPow(long long a, long long b){
//    long long sol = 1;
//    while(b){
//        if(b&1){
//            sol = sol*a;
//        }
//        a = a*a;
//        b >>= 1;
//    }
//    return sol;
//}

//int binarySearch(int x, int n){
//    int step,i;
//    for(step = 1;step <= n;step <<= 1);
//    for(i = 0;step;step >>= 1){
//        if(i + step <= n && v[i+step] <= x){
//            i += step;
//        }
//    }
//    return i;
//}

//void sieve(int n){
//    int i,j;
//    for(i = 4;i <= n;i += 2){
//        ciur[i] = 1;
//    }
//    for(i = 3;i <= n;i += 2){
//        if(!ciur[i]){
//            for(j = 3*i;j <= n;j += i+i){
//                ciur[j] = 1;
//            }
//        }
//    }
//}

//inline int gcd(int a, int b){
//    if(b == 0) return a;
//    return gcd(b,a%b);
//}