对于这道题,我的思路对了,但是读入的时候点的坐标必须是浮点型的数据。
还有在qsort的comp函数返回值是int型的,
所以对于double型的比较应该用关系运算符<和>来表示大小关系,
代码如下:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define M 10010
typedef struct{
double x, y;
}point;
int n;
point po[M];
int comp(const void *a, const void *b)
{
point *aa = (point*)a, *bb = (point*)b;
if(aa->x!=bb->x) return aa->x>bb->x;
return aa->y>bb->y;
}
int main ()
{
double min, x, y, tt;
while(scanf("%d",&n), n)
{
for(int i = 0; i < n; i++) scanf("%lf%lf",&po[i].x,&po[i].y);
qsort(po,n,sizeof(po[0]),comp);
min = 10000.0;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
x = fabs(po[j].x-po[i].x);
y = fabs(po[j].y-po[i].y);
if(x>=min||x>=10000.0) break;//剪枝
if(y>=min||y>=10000.0) continue;//剪枝
tt = sqrt(x*x+y*y);
if(tt>=10000.0) continue;
min = min>tt?tt:min;
}
}
if(min==10000.0) printf("INFINITY\n");
else printf("%.4lf\n",min);
}
return 0;
}