SOS!求检查程序,到17个点距离之和最小的点的坐标
各位高手,菜鸟我编了个程序,程序是:十七个点的坐标已知,在平面(21430250<x<21433500),(4570250<y<4572500)区间内求一个点,使得(x,y)到这十七个点的距离之和最小。程序可以运行,但是结果是错的。
麻烦高手检查检查,错误的话请指出那里出错了,在线等!!
#include<stdio.h>
#include<math.h>
void main()
{int i,x1,y1,s,sum1,sum2,s0,x,y;
int A[17]={21431240,21431280,21431330,21431390,21431480,21431590,21430780,21430780,21430830,21430880,21431980,21432080,21432190,21432270,21430430,21432730,21432880};
int B[17]={4571936,4571746,4571544,4571355,4571153,4570975,4571355,4571165,4570963,4570726,4571740,4571550,4571408,4571218,4570572,4571592,4571456};
for(i=0;i<17;i++)
{
sum1=0;
x1=A[i];
y1=B[i];
s0=(21430250-x1)*(21430250-x1)+(4570250-y1)*(4570250-y1);
sum1=sum1+s0;
}
for(x=21430250;x<21433500;x++)
{
for(y=4570250;y<4572500;y++)
{
for(i=0;i<17;i++)
{
sum2=0;
x1=A[i];
y1=B[i];
s=(x-x1)*(x-x1)+(y-y1)*(y-y1);
sum2=sum2+s;
}
if (sum2<sum1)
sum1=sum2;
else sum1=sum1;
}
}
printf("x=%d\n",x);
printf("y=%d\n",y);
}