zoukankan      html  css  js  c++  java
  • hd1007

    #include <iostream>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    
    struct node
    {
    double x,y;
    }point[100000];
    int n;
    
    bool hAlignLess(node p1,node p2)
    {
    if(p1.x != p2.x) return p1.x < p2.x;
    else return p1.y < p2.y;
    }
    
    double getDist(node p1, node p2)
    {
    return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
    }
    
    double getMin(double a, double b)
    { 
    return a<b?a:b;
    }
    
    double solve(int l,int r)
    {
        if(l == r)
           return 1000000000;
        if(l == r - 1)
           return getDist(point[l],point[r]);
        if(l == r - 2)
           return getMin(getMin(getDist(point[l],point[l+1]),getDist(point[l+1],point[l+2])),getDist(point[l],point[l+2]));
        int i,j,mid = (l+r) >> 1;
        double curmin = getMin(solve(l,mid),solve(mid+1,r));
        for(i=l;i<=r;i++)
           for(j=i+1;j<=i+5 && j<=r;j++)
           {
            curmin = getMin(curmin,getDist(point[i],point[j]));
           }
        return curmin;
    }
    
    int main() {
        int i;
        while(scanf("%d",&n)!=EOF && n){
           for(i = 0; i < n; i++){
                scanf("%lf %lf",&point[i].x,&point[i].y);
           }
           sort(point,point+n,hAlignLess);
           double ans = solve(0,n-1);
           printf("%.2lf
    ",ans/2);
        }
        return 0;
    }
  • 相关阅读:
    图表插件echars的使用案例
    安装Eclipse
    ef 更新数据库
    webapi Route 特性
    WebSite下创建webapi
    C# 泛型约束
    Session共享
    ubuntu eclipse 无法打开
    C# TreeView 连续点击 不触发AfterCheck事件
    ef 仓储模式 Redis
  • 原文地址:https://www.cnblogs.com/Alandre/p/3426558.html
Copyright © 2011-2022 走看看