zoukankan      html  css  js  c++  java
  • [HDU 1007] Quoit Design

    Quoit Design

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

    Total Submission(s): 33577    Accepted Submission(s): 8800 

    Problem Description
    Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded. In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.
    Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
     
    Input
    The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.
     
    Output
    For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places. 
     
    Sample Input
    2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
     
    Sample Output
    0.71 0.00 0.75

    存点的下标比存点快得多、- -

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    using namespace std;
    #define INF 1e20
    #define N 100010
    
    struct Point
    {
        double x,y;
    };
    
    int n;
    Point p[N];
    int tmp[N];
    
    double dis(int a,int b)
    {
        return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
    }
    bool cmp(Point a,Point b)
    {
        if(a.x!=b.x)return a.x<b.x;
        return a.y<b.y;
    }
    bool cmpy(int a,int b)
    {
        return p[a].y<p[b].y;
    }
    
    double solve(int l,int r)
    {
        if(l==r) return INF;               //一个点的情况
        if(l+1==r) return dis(l,r);        //两个点的情况
        int m=(l+r)>>1;
        double d1=solve(l,m);
        double d2=solve(m+1,r);
        double d=min(d1,d2);
        int k=0;
        for(int i=l;i<=r;i++)              //分离出宽度为d的区间
        {
            if(fabs(p[m].x-p[i].x)<=d)
                tmp[++k]=i;
        }
        sort(tmp+1,tmp+k+1,cmpy);
        for(int i=1;i<=k;i++)              //线性扫描 ,判断是否有小于d的距离,由于是按y排序的,所以省去了不少步骤
        {
            for(int j=i+1;j<=k && p[tmp[j]].y-p[tmp[i]].y<d;j++)
            {
                d=min(d,dis(tmp[i],tmp[j]));
            }
        }
        return d;
    }
    int main()
    {
        while(scanf("%d",&n) && n)
        {
            for(int i=1;i<=n;i++)
            {
                scanf("%lf%lf",&p[i].x,&p[i].y);
            }
            sort(p+1,p+n+1,cmp);
            printf("%.2f
    ",solve(1,n)/2);
        }
        return 0;
    }
    趁着还有梦想、将AC进行到底~~~by 452181625
  • 相关阅读:
    【Linux】Gitlab库已损坏前端显示500错误解决方法
    【linux】gitlab 的安装以及数据迁移
    【PHP】图片转换为base64,经过post传输后‘+’会变成 ‘空格’
    【Mac】解决外接显示器时无法用键盘调节音量
    【Mac】 /usr/local 文件夹权限问题
    学妹问的Spring Bean常用配置,我用最通俗易懂的讲解让她学会了
    上海月薪 1w 和家乡月薪 5000 你选择哪?
    30岁码农的一次面试经历:不委屈自己
    写4条宝贵的经验,给初入职场的你
    Java 8 Optional 良心指南,建议收藏
  • 原文地址:https://www.cnblogs.com/hate13/p/4160111.html
Copyright © 2011-2022 走看看