hdu 1007 Quoit Design

Quoit Design

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


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:  1006 1009 1005 1008 1004 
/*
  最小点距离问题 
  采用分治算法,假设对于1-n的区间,我们已经求出1~m(m是中点)和m+1~n的结果分别是d1和d2,
  那么如果1~n的答案出现在这两个单独的区间内,很明显就是min(d1,d2),否则在两个区间之间产生。
  如果直接两重循环枚举两个区间的数会T,所以考虑优化:
  ①:如果某个点到m的距离大于min(d1,d2),那么不考虑。
  ②:首先用到一个结论:
        假设有一个点q,坐标是xq, yq。可以证明在以q为底边中点,长为2d,宽为d的矩形区域内不会有超过6个点
        (证明见算法导论,然而我并没看懂,Orz)
      有了这个结论之后,我们将第一次优化后的点按照y排序,对于一个点i,如果某个点j与i的y坐标之差大于之前求出的ans,
      那么j之后的就不用计算了。(不是很明白复杂度的证明) 
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
#define pf(x) ((x)*(x))
using namespace std;
const int N=1e5+10;
struct node{
    double x,y;
}qx[N],qy[N];
int n;
bool cmpx(const node &a,const node &b){
    return a.x<b.x;
}
bool cmpy(const node &a,const node &b){
    return a.y<b.y;
}
double getdis(const node &a,const node &b){
    return sqrt(pf(a.x-b.x)+pf(a.y-b.y));
}
double solve(int l,int r){
    if(l+1==r) return getdis(qx[l],qx[r]);
    if(l+2==r) return min(getdis(qx[l],qx[r]),min(getdis(qx[l],qx[l+1]),getdis(qx[l+1],qx[r])));
    int mid=l+r>>1,cnt=0;
    double ans=min(solve(l,mid),solve(mid+1,r));
    for(int i=l;i<=r;i++){
        if(fabs(qx[i].x-qx[mid].x)<=ans){
            qy[++cnt]=qx[i];
        }
    }
    sort(qy+1,qy+cnt+1,cmpy);
    for(int i=1;i<=cnt;i++){
        for(int j=i+1;j<=cnt;j++){
            if(qy[j].y-qy[i].y>=ans) break;
            ans=min(ans,getdis(qy[i],qy[j]));
        }
    }
    return ans;
}
void work(){
    for(int i=1;i<=n;i++) scanf("%lf%lf",&qx[i].x,&qx[i].y);
    sort(qx+1,qx+n+1,cmpx);
    printf("%.2lf\n",solve(1,n)/2);
}
int main(){
    while(scanf("%d",&n)==1&&n) work();
    return 0;
} 

 

posted @ 2017-01-13 16:31  神犇(shenben)  阅读(168)  评论(0编辑  收藏  举报