题意:给出球面上两点的经纬度,注意分跟秒进制是60进制的,让求球面上的两点距离。
有公式 r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2)) 。
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; double Dis3D(double a1,double b1,double a2,double b2,double r) { return r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2)); } double geta(double x1,double x2,char *s) { double a=x1+x2/60.0; if(s[0]=='W'||s[0]=='S') a=-a; a=a*acos(-1.0)/180; return a; } int main() { double x1,x2,y1,y2; char s1[3],s2[3]; while(~scanf("%lf%lf%s%lf%lf%s",&x1,&x2,s1,&y1,&y2,s2)) { double a1=geta(x1,x2,s1),b1=geta(y1,y2,s2); scanf("%lf%lf%s%lf%lf%s",&x1,&x2,s1,&y1,&y2,s2); double a2=geta(x1,x2,s1),b2=geta(y1,y2,s2); printf("%.3f\n",Dis3D(a1,b1,a2,b2,6370)); } return 0; }