uva 11817 - Tunnelling the Earth

题意:从地球上的一个点到另一个点,求两点的球面距离和直线距离之差。假定地球是正球体,半径为6371009米。

 

#include<iostream>

#include<cmath>

#define r 6371009

#define pi 2.0*asin(1.0)



using namespace std;



double ang(double lt1,double lt2,double lg1,double lg2)

{

    return acos(cos(lt1)*cos(lt2)*cos(lg1-lg2)+sin(lt1)*sin(lt2));

}

double dis_line(double lt1,double lt2,double lg1,double lg2)

{

    return r*sqrt(2-2*(cos(lt1)*cos(lt2)*cos(lg1-lg2)+sin(lt1)*sin(lt2)));

}

double dis_sphere(double lt1,double lt2,double lg1,double lg2)

{

    return r*ang(lt1,lt2,lg1,lg2);

}

int main()

{

    int t;

    double lt1,lt2,lg1,lg2;

    cin>>t;

    while(t--)

    {

        cin>>lt1>>lg1>>lt2>>lg2;

        lt1*=pi/180.0;

        lt2*=pi/180.0;

        lg1*=pi/180.0;

        lg2*=pi/180.0;

        long long l=0.5+dis_sphere(lt1,lt2,lg1,lg2)-dis_line(lt1,lt2,lg1,lg2);

        cout<<l<<endl;

    }

    return 0;

}


 

 

你可能感兴趣的:(uva)