您的位置:首页 > 其它

1007

2010-11-05 20:39 162 查看
二分思想:
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

struct point{
double x,y;
bool operator <(point other)const{
return x<other.x||(x==other.x&&y<other.y);
}
} p[100000],tp[100000];
bool cmpy(point a, point b){
return a.y<b.y;
}
double Gao(int s,int e){
if(s==e) return 1e100;
int m=(s+e)/2;
double l=Gao(s,m);
double r=Gao(m+1,e);
double ans=min(l,r);
int cnt=0;
for(int i=s; i<=m; ++i){
if(p[m].x-p[i].x<ans){
tp[cnt++]=p[i];
}
}
for(int i=m+1; i<=e; ++i){
if(p[i].x-p[m+1].x<ans)
tp[cnt++]=p[i];
}
sort(tp,tp+cnt,cmpy);
for(int i=0; i<cnt; ++i){
for(int j=i+1; j<cnt; ++j){
if(tp[j].y-tp[i].y>=ans)
break;
ans=min(sqrt((tp[i].x-tp[j].x)*(tp[i].x-tp[j].x)+(tp[i].y-tp[j].y)*(tp[i].y-tp[j].y)),ans);
}
}
return ans;
}
int main(){
int n;
while(scanf("%d",&n)){
if(n==0)
break;
for(int i=0; i<n; ++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n);
printf("%.2lf/n",Gao(0,n-1)/2);
fflush(stdout);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: