portal
El significado de los problemas
N tiene el juguetes de tono, distribuidos en diferentes lugares, tiene un radio r del anillo, pero el anillo puede atrapar un juguete, simplemente, en un círculo de radio r no puede contener dos juguete, este buscan el mayor r, 2r es inferior a los dos puntos más cercanos, a fin de hacer máxima r. En el punto más cercano problema.
código:
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1e5+5;
struct Point{
double x,y;
}p[MAXN];
int temp[MAXN];
bool cmpx(const Point &a,const Point &b){
return a.x<b.x;
}
bool cmpy(const int &a,const int &b){
return p[a].y<p[b].y;
}
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));
}
double min(double a,double b){//重载min函数
return a<b?a:b;
}
double closestPair(int l,int r)
{
if(r==l) return (1<<30);//只有一个点返回无穷大
if(r-l==1) return dis(l,r);
int mid=(r+l)>>1;
double d1=closestPair(l,mid);//递归左边
double d2=closestPair(mid+1,r);
double d=min(d1,d2);
int cnt=0;
for(int i=l;i<=r;i++)
if(fabs(p[i].x-p[mid].x)<d) temp[cnt++]=i;
sort(temp,temp+cnt,cmpy);
for(int i=0;i<cnt;i++)
for(int j=i+1;j<=i+6 && j<cnt;j++){
if(p[temp[j]].y-p[temp[i]].y>=d) break;
d=min(d,dis(temp[i],temp[j]));
}
return d;
}
int main(){
int n;
while(scanf("%d",&n),n){
for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpx);//对点进行x轴排序
printf("%.2f\n",closestPair(0,n-1)/2);
}
return 0;
}