题目:给你地球上两点的经度和纬度,计算球面最近距离。
分析:计算几何、大地坐标系。利用公式计算连点间距离,再转化成弧长即可。
d = r*sqrt(2-2*(cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2))) (推导见11817)
弧长:s = 2*asin(d/(2*r))*r
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { double r = 6371.01; double p = acos(-1.0); int n; char ch; double a,b,c,A1,B1,A2,B2; while ( scanf("%d",&n) != EOF ) while ( n -- ) { scanf("%lf%lf%lf %c",&a,&b,&c,&ch); A1 = a+b/60.0+c/3600.0; if ( ch == 'S' ) A1 *= -1; A1 *= p/180.0; scanf("%lf%lf%lf %c",&a,&b,&c,&ch); B1 = a+b/60.0+c/3600.0; if ( ch == 'W' ) B1 *= -1; B1 *= p/180.0; scanf("%lf%lf%lf %c",&a,&b,&c,&ch); A2 = a+b/60.0+c/3600.0; if ( ch == 'S' ) A2 *= -1; A2 *= p/180.0; scanf("%lf%lf%lf %c",&a,&b,&c,&ch); B2 = a+b/60.0+c/3600.0; if ( ch == 'W' ) B2 *= -1; B2 *= p/180.0; double d = r*sqrt(2-2*(cos(A1)*cos(A2)*cos(B1-B2)+sin(A1)*sin(A2))); printf("%.2lf\n",2*asin(d/(2*r))*r); } return 0; }