Airline HubSubmit: 712 Accepted:133Time Limit: 1000MS Memory Limit: 65536KDescription
World Wide Flyer has landing rights at several airports throughout the world. They wish to place their central hub at the airport that minimizes the maximum direct flying distance from the hub to any other airport in the world.
Input
Input consists of a line containing n <= 1000, the number of airports. n lines follow, each giving the latitude (between -90 and +90 degrees) and longitude (between -180 and +180 degrees) of an airport.
Output
To two decimal places, give the latitude and longitude of the airport that best serves as a hub. If there are several any one will do.
Sample Input
3
3.2 -15.0
20.1 -175
-30.2 10
Sample Output
3.20 -15.00
Source
Waterloo local 2000.01.29
CODE:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int n,i,j,temp;
double right;
double PI=acos(-1);
scanf("%d\n",&n);
double **a=(double **)malloc(n*sizeof(double *));
for(i=0;i<n;i++)
{
a[i]=(double *)malloc(2*sizeof(double));
}
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%lf",*(a+i)+j);
*(*(a+i)+j)=*(*(a+i)+j)*PI/180;
}
}
double **b=(double **)malloc(n*sizeof(double*));//三维数组b,计算坐标
for(i=0;i<n;i++)
b[i]=(double*)malloc(3*sizeof(double));
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
b[i][0]=cos(a[i][0])*cos(a[i][1]);
b[i][1]=cos(a[i][0])*sin(a[i][1]);
b[i][2]=sin(a[i][0]);
}
}
double *c=(double *)malloc(n*sizeof(double));
for(i=0;i<n;i++)
c[i]=0;
for(i=0;i<n;i++)
{
for(j=0;j!=i;j++)
{
c[i]=c[i]+acos(b[i][0]*b[j][0]+b[i][1]*b[j][1]+b[i][2]*b[j][2]);
}
}
right=c[0];
for(i=0;i<n;i++)
{
if(c[i]<=right)
{
right=c[i];
temp=i;
}
}
printf("%lf %lf\n",a[temp][0]*180/PI,a[temp][1]*180/PI);
return 0;
}
总是WA,不知道问题出在哪儿。。。。。。。。。。。。。。。。。。。。。。。。。。。