hdu1007Quoit Design

Quoit Design

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


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. 
 


题目大意:
      给你n个点让你求出这些点内存在的最短距离,小于等于任意两点的距离;
解题思路:
 将所有点不断的分为两堆:如s1、s2。则最短距离存在于s1集合或者s2集合或者介于两集合之间的点,如果是介于两集合之间的话,这两个点必满足m-distance<x1、x2> m+distance 然后递归求解。

 如果你看了我的上一篇《平面最短距离点对》那么对于这题来说就是实践了,所以不再明说,不理解的可以先翻看我的上篇博客;
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespacestd;
#define N 100010

structnode{//保存所有的点

double x,y;

}p[N];

node temp[N];

double cmpx(node a,nodeb)//按横坐标排序函数
{
   return a.x
}

double cmpy(node a,nodeb)//按纵坐标排序函数
{
   return a.y
}

double dis(node a,nodeb)//求两点距离
{
   return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double dp(int s,int e){//区间范围[s   e]
   if(e-s==1)
       return dis(p[s],p[e]);
      if(e-s==2)
          return min(dis(p[s],p[s+1]),min(dis(p[s],p[e]),dis(p[s+1],p[e])));
   int mid=(s+e)/2;
   double MIN =min(dp(s,mid),dp(mid+1,e));

   //找出可能分别位于集合s1、s2中的候选点

   for(int i=mid-1;i>=s;i--){
      if(p[mid].x-p[i].x>=MIN){
          s=i;
          break;
      }
   }
   for(int i=mid;i<=e;i++){
      if(p[i].x-p[mid].x>=MIN){
          e=i;
          break;
      }
   }
   int j=0;

   for(int i=s;i<=e;i++){
      temp[j++]=p[i];
   }
   //将候选点按纵坐标排列
   sort(temp,temp+j,cmpy);
   //找到最终的最短点
   for(int i=0;i
     for(int k=i+1;k
         if(temp[k].y-temp[i].y>MIN)break;
          MIN=min(MIN,dis(temp[i],temp[k]));
   }
   return MIN;
}
int main()
{
   int n;
   while(scanf("%d",&n) &&n)
   {
       for(inti=0;i
         scanf("%lf%lf",&p[i].x,&p[i].y);
      sort(p,p+n,cmpx);
      printf("%.2lf\n",dp(0,n-1)/2);

   }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值