UVA 11817 Tunnelling the Earth

本文探讨了在地球表面计算两点间距离的方法,包括球面距离和直线距离的计算公式,并通过实例展示了算法的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

经度维度计算球面距离以及直线距离。模板模板。。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")

using namespace std;

const double pi = acos(-1.0);
const double R = 6371009;
double angle_3d(double lng1, double lat1, double lng2, double lat2)
{
    double dlng = fabs(lng1 - lng2)*pi/180;
    while( dlng >= 2*pi )
        dlng -= pi*2;
    if( dlng > pi )
        dlng = 2*pi - dlng;
    lat1 *= pi/180;
    lat2 *= pi/180;
    return acos(cos(lat1)*cos(lat2)*cos(dlng) + sin(lat1)*sin(lat2));
}

int main()
{
    int ncases;
    double la,lb,wa,wb;
    
    scanf("%d", &ncases);
    
    while( ncases-- )
    {
        scanf("%lf%lf%lf%lf",&la, &wa, &lb, &wb);
        double ang = angle_3d(wa, la, wb, lb);
        double l1 = ang*R;
        double l2 = R*sqrt(2 - 2*cos(ang));
        printf("%.0lf\n", l1 - l2);
    }

return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值