zoukankan      html  css  js  c++  java
  • 【HDU 1007】 Quoit Design

    【题目链接】

                 http://acm.hdu.edu.cn/showproblem.php?pid=1007

    【算法】

              答案为平面最近点对距离除以2

    【代码】

              

    #include <algorithm>  
    #include <bitset>  
    #include <cctype>  
    #include <cerrno>  
    #include <clocale>  
    #include <cmath>  
    #include <complex>  
    #include <cstdio>  
    #include <cstdlib>  
    #include <cstring>  
    #include <ctime>  
    #include <deque>  
    #include <exception>  
    #include <fstream>  
    #include <functional>  
    #include <limits>  
    #include <list>  
    #include <map>  
    #include <iomanip>  
    #include <ios>  
    #include <iosfwd>  
    #include <iostream>  
    #include <istream>  
    #include <ostream>  
    #include <queue>  
    #include <set>  
    #include <sstream>  
    #include <stdexcept>  
    #include <streambuf>  
    #include <string>  
    #include <utility>  
    #include <vector>  
    #include <cwchar>  
    #include <cwctype>  
    #include <stack>  
    #include <limits.h> 
    using namespace std;
    #define MAXN 100010
    const double INF = 1e10;
    
    struct info
    {
            double x,y;        
    } a[MAXN];
    
    int n,i;
    
    inline bool cmpx(info a,info b) 
    {
            return a.x < b.x;
    }
    inline bool cmpy(info a,info b)
    {
            return a.y < b.y;
    }
    inline double dist(info p,info q)
    {
            return sqrt(abs(p.x - q.x) * abs(p.x - q.x) + abs(p.y - q.y) * abs(p.y - q.y));
    }
    inline double Closest_Pair(int l,int r)
    {
            int i,j,mid,len = 0;
            static info s[MAXN];
            double d;
            if (l == r) return INF; 
            if (l + 1 == r) return dist(a[l],a[r]);
            mid = (l + r) >> 1;
            d = min(Closest_Pair(l,mid),Closest_Pair(mid+1,r));
            for (i = l; i <= r; i++)
            {
                    if (abs(a[mid].x - a[i].x) <= d) s[++len] = a[i];    
            }        
            sort(s+1,s+len+1,cmpy);
            for (i = 1; i <= len; i++)
            {
                    for (j = i + 1; j <= len && s[j].y - s[i].y <= d; j++)
                    {
                            d = min(d,dist(s[i],s[j]));
                    }
            }
            return d;
    }
    
    int main() 
    {
            
            while (scanf("%d",&n) && n)
            {
                    for (i = 1; i <= n; i++) scanf("%lf%lf",&a[i].x,&a[i].y);
                    sort(a+1,a+n+1,cmpx);
                    printf("%.2lf
    ",Closest_Pair(1,n) / 2.0);
            }
            
            return 0;
        
    }
  • 相关阅读:
    linux网络编程之扫盲
    当lov变化时得到lov变化的值
    动态设置OAMessageChoiceBean值
    RSA host key for HOST has changed and you have requested strict checking
    64位整数的编译错误
    CSS让内容水平居中(固定宽度)
    如何计算亮度值
    adb新参数支持Android 2.2安装到SD卡上
    NSDateFormatter formatting
    Win7系统下Safari不能打开网页的解决方法
  • 原文地址:https://www.cnblogs.com/evenbao/p/9240696.html
Copyright © 2011-2022 走看看