杭电acm 1007题被Compilation Error
#include<stdio.h>#include<stdlib.h>#include<math.h>structPoint{doublex,y;}arrP[99999]...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct Point
{
double x,y;
}arrP[99999],arrX[99999],arrY[99999];
int compx(const void *a,const void *b)
{
if(((struct Point *)a)->x==((struct Point *)b)->x)
return ((struct Point *)a)->y<((struct Point *)b)->y?1:-1;
return ((struct Point *)a)->x<((struct Point *)b)->x?1:-1;
}
int compy(const void *a,const void *b)
{
if(((struct Point *)a)->y==((struct Point *)b)->y)
return ((struct Point *)a)->x<((struct Point *)b)->x?1:-1;
return ((struct Point *)a)->y<((struct Point *)b)->y?1:-1;
}
double GetDistance(struct Point a,struct Point b)
{
return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0));
}
double MinDistance(double a,double b)
{
return a<=b?a:b;
}
double GetMinDistance(int l,int r)
{
if(l==r)
return 0;
else if(l+1==r)
return GetDistance(arrP[l],arrP[r]);
else if(l+2==r)
{
double tmp1=GetDistance(arrP[l],arrP[l+1]);
double tmp2=GetDistance(arrP[l],arrP[r]);
double tmp3=GetDistance(arrP[r],arrP[l+1]);
return MinDistance(MinDistance(tmp1,tmp2),tmp3);
}
int middle,j,k,i;
middle=(l+r)/2;j=0;k=0;
double minDistance=MinDistance(GetMinDistance(l,middle),GetMinDistance(middle,r));
for(i=l;i<=r;i++)
{
if(fabs(arrP[i].x-arrP[middle].x)<minDistance)
arrX[j++]=arrP[i];
}
qsort(arrX,j,sizeof(struct Point),compy);
middle=(j+1)/2;
for(i=0;i<j;i++)
{
if(fabs(arrX[i].y-arrX[middle].y)>minDistance)
arrY[k++]=arrX[i];
}
for(i=0;i<k;i++)
for(j=i+1;j<k;j++)
{
double tmpDistance=GetDistance(arrY[i],arrY[j]);
if(tmpDistance<minDistance)
minDistance=tmpDistance;
}
return minDistance;
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF&&n)
{
//Point p;
for(i=0;i<n;i++)
scanf("%lf%lf",&arrP[i].x,&arrP[i].y);
qsort(arrP,n,sizeof(struct Point),compx);
double minDistance;
minDistance=GetMinDistance(0,n-1);
printf("%.2lf\n",minDistance/2);
}
return 0;
}
Compilation Error
0_0_10372321_11217.c
0_0_10372321_11217.c(41) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
0_0_10372321_11217.c(42) : error C2065: “middle” : 未声明的标识符
0_0_10372321_11217.c(42) : error C2065: “j” : 未声明的标识符
0_0_10372321_11217.c(42) : error C2065: “k” : 未声明的标识符
0_0_10372321_11217.c(43) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
0_0_10372321_11217.c(44) : error C2065: “i” : 未声明的标识符
0_0_10372321_11217.c(46) : error C2065: “minDistance” : 未声明的标识符
0_0_10372321_11217.c(74) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面) 展开
#include <stdlib.h>
#include <math.h>
struct Point
{
double x,y;
}arrP[99999],arrX[99999],arrY[99999];
int compx(const void *a,const void *b)
{
if(((struct Point *)a)->x==((struct Point *)b)->x)
return ((struct Point *)a)->y<((struct Point *)b)->y?1:-1;
return ((struct Point *)a)->x<((struct Point *)b)->x?1:-1;
}
int compy(const void *a,const void *b)
{
if(((struct Point *)a)->y==((struct Point *)b)->y)
return ((struct Point *)a)->x<((struct Point *)b)->x?1:-1;
return ((struct Point *)a)->y<((struct Point *)b)->y?1:-1;
}
double GetDistance(struct Point a,struct Point b)
{
return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0));
}
double MinDistance(double a,double b)
{
return a<=b?a:b;
}
double GetMinDistance(int l,int r)
{
if(l==r)
return 0;
else if(l+1==r)
return GetDistance(arrP[l],arrP[r]);
else if(l+2==r)
{
double tmp1=GetDistance(arrP[l],arrP[l+1]);
double tmp2=GetDistance(arrP[l],arrP[r]);
double tmp3=GetDistance(arrP[r],arrP[l+1]);
return MinDistance(MinDistance(tmp1,tmp2),tmp3);
}
int middle,j,k,i;
middle=(l+r)/2;j=0;k=0;
double minDistance=MinDistance(GetMinDistance(l,middle),GetMinDistance(middle,r));
for(i=l;i<=r;i++)
{
if(fabs(arrP[i].x-arrP[middle].x)<minDistance)
arrX[j++]=arrP[i];
}
qsort(arrX,j,sizeof(struct Point),compy);
middle=(j+1)/2;
for(i=0;i<j;i++)
{
if(fabs(arrX[i].y-arrX[middle].y)>minDistance)
arrY[k++]=arrX[i];
}
for(i=0;i<k;i++)
for(j=i+1;j<k;j++)
{
double tmpDistance=GetDistance(arrY[i],arrY[j]);
if(tmpDistance<minDistance)
minDistance=tmpDistance;
}
return minDistance;
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF&&n)
{
//Point p;
for(i=0;i<n;i++)
scanf("%lf%lf",&arrP[i].x,&arrP[i].y);
qsort(arrP,n,sizeof(struct Point),compx);
double minDistance;
minDistance=GetMinDistance(0,n-1);
printf("%.2lf\n",minDistance/2);
}
return 0;
}
Compilation Error
0_0_10372321_11217.c
0_0_10372321_11217.c(41) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
0_0_10372321_11217.c(42) : error C2065: “middle” : 未声明的标识符
0_0_10372321_11217.c(42) : error C2065: “j” : 未声明的标识符
0_0_10372321_11217.c(42) : error C2065: “k” : 未声明的标识符
0_0_10372321_11217.c(43) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
0_0_10372321_11217.c(44) : error C2065: “i” : 未声明的标识符
0_0_10372321_11217.c(46) : error C2065: “minDistance” : 未声明的标识符
0_0_10372321_11217.c(74) : error C2143: 语法错误 : 缺少“;”(在“类型”的前面) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询