hdu 1007

点击打开资料

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

const int MAXN = 100100;

struct Point
{
	double x, y;
};

Point point[MAXN];
Point s[MAXN];
int cmp(Point a, Point b)
{
	return a.x < b.x;
}

int cmp1(Point a, Point b)
{
	return a.y < b.y;
}

double Calculate(Point a, Point b)
{
	return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );
}


double Binary_search(int a, int b)
{
	int i, j;
	if(b - a == 1)
		return Calculate(point[a], point[b]);
	if(b - a == 2)
		return min( Calculate(point[a], point[a+1]), min(Calculate(point[a], point[b]), Calculate(point[a+1], point[b])) );
	int mid = (a + b) / 2;
	double m = min(Binary_search(a, mid), Binary_search(mid+1, b));
	for(i = mid-1; i >= a; --i)
	{
		if (point[mid].x - point[i].x >= m)
		{
			a = i;
			break;
		}
	}
	for (i = mid; i <= b; ++i)
	{
		if (point[i].x - point[mid-1].x >= m)
		{
			b = i;
			break;
		}
	}
	int cnt = 0;
	for (i = a; i <= b; ++i)
		s[cnt++] = point[i];
	sort(s, s+cnt, cmp1);
	for (i = 0; i < cnt; ++i)
	{
		for (j = i+1; j < cnt; ++j)
		{
			if(s[j].y - s[i].y > m)//在中位线上的投影小于m的值
				break;
			if(Calculate(s[i], s[j]) < m)
				m = Calculate(s[i], s[j]);
		}
	}
	return m;
}

int main()
{
	int n;
	while (cin>>n, n)
	{
		for (int i = 0; i < n; ++i)
			cin>>point[i].x>>point[i].y;
		sort(point, point+n, cmp);
		cout<<setiosflags(ios::fixed)<<setprecision(2)<<Binary_search(0, n-1)/2<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值