zoukankan      html  css  js  c++  java
  • UVA 11817 Tunnelling the Earth --球面距离公式

    题意: 给出两点的经纬度,求两点的球面距离与直线距离之差。

    解法: 我们先算出球面距离,然后可以根据球面距离算出直线距离。

    球面距离公式: R*acos(sin(W1)*sin(W2)+cos(W1)*cos(W2)*cos(J1-J2));   ( W1,W2 为两点的纬度值,J1,J2为两点的经度值 )

    推导过程就不写了,网上可以查到很明确的推导过程。

    然后算出了球面距离,其实就是一段弧,根据弧长求弦长:

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #define pi acos(-1.0)
    using namespace std;
    
    int main()
    {
        int t,n,i;
        double x1,x2,y1,y2;
        double R = 6371009;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf%lf",&x1,&y1);
            scanf("%lf%lf",&x2,&y2);
            x1 = x1*pi/180.0;
            y1 = y1*pi/180.0;
            x2 = x2*pi/180.0;
            y2 = y2*pi/180.0;
            double ans = R*acos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y1-y2));
            printf("%.0f
    ",ans-2*R*sin(ans/(2*R)));
        }
        return 0;
    }
    View Code
  • 相关阅读:
    python调用函数
    python递归函数的执行过程
    linux rwx 权限说明
    linux ssh scp免密码
    linux的bash特性
    python3常用的内置函数
    linux清理系统缓存
    vim常用命令
    公司项目安装禅道
    jquery 自定义动画
  • 原文地址:https://www.cnblogs.com/whatbeg/p/4160447.html
Copyright © 2011-2022 走看看