听师哥说这题数据比较水,所以把横坐标排序排出来之后,再把附近的三个点距离枚举一下就能在HDU上AC......所以,既然这样快就先这样写上喽╮(╯_╰)╭
(表示算距离的函数一开始命名为distance了结果一直报错,原来这个名字是已经有了的啊......改了半天才发现= =)
下面是这个偷懒的方法做出来的AC代码......
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
double d[100005];
struct point
{
double x;
double y;
};
point ap[100005];
double distan(point a,point b)
{
double t;
t=sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
return t;
}
double tmin(double a,double b,double c)
{
double t;
t=a<b?a:b;
if(t<c)
return t;
else
return c;
}
bool cmp(point a,point b)
{
return a.x<b.x;
}
int main()
{
int n;
int i,j;
double temp,ans;
double a,b,c;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%lf%lf",&ap[i].x,&ap[i].y);
}
if(n==2)
{
ans=distan(ap[0],ap[1])/2;
printf("%.2f\n",ans);
continue;
}
sort(ap,ap+n,cmp);
for(i=0;i<n-2;i++)
{
a=distan(ap[i],ap[i+1]);
b=distan(ap[i],ap[i+2]);
c=distan(ap[i+1],ap[i+2]);
d[i]=tmin(a,b,c);
}
for(j=0;j<i-1;j++)
{
if(d[j]<d[j+1])
d[j+1]=d[j];
}
ans=d[j]/2.0;
printf("%.2f\n",ans);
}
return 0;
}
不过,该好好做的还是得好好做= =这题正常的做法应该是用分治法求最近点对的方法来做,方法也是听师哥讲完了,不过感觉写起来好麻烦,先A了在界面上看着比较舒服......至于正常的做法,等想起来再好好写吧,先让我懒一下= =