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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值