1007

二分思想:

#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);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值