zoukankan      html  css  js  c++  java
  • UVa11817

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2917

    模版,测地线距离和直线距离之差

    精度问题令人头疼!

    #include<cstdio>
    #include<cmath>
    using namespace std;
    const double R = 6371009;
    
    double torad(double deg) {
      return deg/180 * M_PI;
    }
    
    void get_coord(double lat, double lng, double& x, double& y, double& z) {
      lat = torad(lat);
      lng = torad(lng);
      x = R*cos(lat)*cos(lng);
      y = R*cos(lat)*sin(lng);
      z = R*sin(lat);
    }
    
    double sqr(double x) { return x*x; }
    
    double dist(double x1, double y1, double z1, double x2, double y2, double z2) {
      return sqrt(sqr(x1-x2)+sqr(y1-y2)+sqr(z1-z2));
    }
    
    int main() {
      int T;
      double lat1, lng1, lat2, lng2;
      double x1, y1, z1, x2, y2, z2;
      scanf("%d", &T);
      while(T--) {
        scanf("%lf%lf%lf%lf", &lat1, &lng1, &lat2, &lng2);
        get_coord(lat1, lng1, x1, y1, z1);
        get_coord(lat2, lng2, x2, y2, z2);
        double d = dist(x1, y1, z1, x2, y2, z2);
        double d2 = 2*asin(d/(2*R))*R;
        printf("%.0lf\n", d2-d);
      }
      return 0;
    }



  • 相关阅读:
    Spring Boot自动配置
    Servlet、JSP总结(1)
    Spring MVC
    Springboot中的数据库事务
    数据库访问
    AOP
    全注解下的IOC
    spring boot入门
    安卓工程化开发笔记(2)
    2048功能说明模板
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3111302.html
Copyright © 2011-2022 走看看