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): 25335    Accepted Submission(s): 6716


    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
     
    Author
    CHEN, Yue
     
    Source
     
    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1024 1016 3629 1044 1147 
     
     1 //1468MS    2288K    1378 B    G++
     2 /*
     3 
     4     题意;
     5         给出n个点,求最近的两个点的距离的一般
     6         
     7     最近点对:
     8         要用到分治的思想做,是时间复杂度为O(nlgn),直接求会超时
     9         最近点对问题在很多算法书和资料上都有讲到,主要思想是分治。 
    10     
    11     注意一点: 用C的 qsort排序一直TLE,表示有点无力.. 
    12 
    13 */
    14 #include<iostream>
    15 #include<algorithm>
    16 #include<stdio.h>
    17 #include<math.h>
    18 #define N 100005
    19 using namespace std;
    20 struct node{
    21     double x,y;       
    22 }p[N];
    23 int a[N];
    24 int n;
    25 double cmpx(node a,node b)
    26 {
    27     return a.x<b.x;
    28 }
    29 double cmpy(int a,int b)
    30 {
    31     return p[a].y<p[b].y;
    32 }
    33 inline double Max(double a,double b)
    34 {
    35     return a>b?a:b;
    36 }
    37 inline double Min(double a,double b)
    38 {
    39     return a<b?a:b;
    40 }
    41 inline double Dis(node a,node b)
    42 {
    43     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    44 }
    45 double find(int l,int r)
    46 {
    47     if(l==r) return 0x7ffffff; 
    48     if(r==l+1) return Dis(p[l],p[r]);
    49     if(r==l+2) return Min(Dis(p[l],p[r]),Min(Dis(p[l],p[l+1]),Dis(p[l+1],p[r])));
    50     int mid=(l+r)>>1;
    51     double d=Min(find(l,mid),find(mid+1,r));
    52     int cnt=0;
    53     for(int i=l;i<=r;i++){
    54         if(p[i].x>=p[mid].x-d && p[i].x<=p[mid].x+d)
    55             a[cnt++]=i;
    56     }
    57     sort(a,a+cnt,cmpy);
    58     for(int i=0;i<cnt;i++){
    59         for(int j=i+1;j<cnt;j++){
    60             if(p[a[j]].y-p[a[i]].y>=d) break;
    61             d=Min(d,Dis(p[a[i]],p[a[j]]));
    62         }
    63     }
    64     return d;
    65 }
    66 int main(void)
    67 {
    68     while(scanf("%d",&n)!=EOF)
    69     {
    70         if(n==0) break;
    71         for(int i=0;i<n;i++)
    72             scanf("%lf%lf",&p[i].x,&p[i].y);
    73         sort(p,p+n,cmpx);
    74         printf("%.2lf
    ",find(0,n-1)/2);
    75     }
    76     return 0;
    77 }
  • 相关阅读:
    TextSharp详情
    Java使用Itext5.5.10进行pdf签章
    java生成PDF,各种格式、样式、水印都有
    使用itext直接替换PDF中的文本
    在Asp.Net中操作PDF – iTextSharp
    使用iTextSharp修改PDF文件(一)
    微信公众平台HTTPS方式调用配置免费https服务器
    ef SQL Server 版本不支持数据类型“datetime2”
    开源框架.netCore DncZeus学习(三)增加一个菜单
    开源框架.netCore DncZeus学习(二)配置连接
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3443630.html
Copyright © 2011-2022 走看看