zoukankan      html  css  js  c++  java
  • HDU-1007-最小公共点对

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

    Quoit Design

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 58813    Accepted Submission(s): 15582


    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
      
      给出n个点,找到一个最大半径的圆,满足这个圆每次最多只能覆盖一个点。输出这个最大圆的半径。显然这个最大半径就是最近公共点对的一半,二分找最近距离就好了。、
       
     1 #include<iostream>
     2 #include<cmath>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<vector>
     7 using namespace std;
     8 #define inf 0x3f3f3f3f
     9 struct Point
    10 {
    11     double x,y;
    12 }P[100010];
    13 inline bool cmpx(Point A,Point B){return A.x<B.x;}
    14 inline bool cmpy(Point A,Point B){return A.y<B.y;}
    15 double dis(Point A,Point B)
    16 {
    17     double dx=(A.x-B.x)*(A.x-B.x);
    18     double dy=(A.y-B.y)*(A.y-B.y);
    19     return sqrt(dx+dy);
    20 }
    21 double solve(int l,int r)
    22 {
    23     if(l==r) return inf;
    24     if(l+1==r) return dis(P[l],P[r]);
    25     vector<Point>vp;
    26     int mid=(l+r)>>1;
    27     double res=min(solve(l,mid),solve(mid+1,r));
    28     for(int i=l;i<=r;++i)
    29         if(P[i].x>=P[mid].x-res&&P[i].x<=P[mid].x+res)
    30           vp.push_back(P[i]);
    31     sort(vp.begin(),vp.end(),cmpy);
    32     for(int i=0;i<vp.size();++i){
    33         for(int j=1;i+j<vp.size()&&j<7;++j){
    34             if(res>dis(vp[i],vp[i+j]))
    35                 res=dis(vp[i],vp[i+j]);
    36         }
    37     }
    38     return res;
    39 }
    40 int main()
    41 {
    42     int n;
    43     while(cin>>n&&n){
    44         for(int i=1;i<=n;++i)
    45             scanf("%lf%lf",&P[i].x,&P[i].y);
    46         sort(P+1,P+1+n,cmpx);
    47         printf("%.2f
    ",solve(1,n)/2.0);
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    swift 第三方库迁移错误解决“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choo
    ios 绘制虚线 CGContextSetLineDash的使用
    在 cell 中获取 textFlied内容的使用
    swift 委托代理传值
    swift3.0基础语法
    webSocket开源框架:SocketRocket 简单的使用
    iOS开发— Socket编程
    常见的 HTTP错误代码大全
    lambda表达式的使用
    浅谈静态代理模式 01
  • 原文地址:https://www.cnblogs.com/zzqc/p/8403969.html
Copyright © 2011-2022 走看看