码迷,mamicode.com
首页 > 其他好文 > 详细

Airline Hub

时间:2016-08-27 23:27:21      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

参考:http://blog.csdn.net/mobius_strip/article/details/12731459

#include <stdio.h>
#include <cmath>
#include <iostream>

struct Point
{
    double lat, lon;
};

double dist(double lat1, double lon1, double lat2, double lon2)
{
    double p = acos(-1.0);
    lat1 *= p / 180.0; lon1 *= p / 180.0;
    lat2 *= p / 180.0; lon2 *= p / 180.0;
    return cos(lat1)*cos(lat2)*cos(lon1 - lon2) + sin(lat1)*sin(lat2);
}

int main()
{
    const int count = 1001;
    static Point pts[count];
    static double dis[count][count];
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i)
    {
        std::cin >> pts[i].lat >> pts[i].lon;
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            dis[i][j] = dis[j][i] = dist(pts[i].lat, pts[i].lon, pts[j].lat, pts[j].lon);
        }
    }
    double min = dis[0][1];
    int hub = 0;
    for (int i = 0; i < n; ++i)
    {
        double max = 0.0;
        for (int j = 0; j < n; ++j)
        {
            if (max < dis[i][j])
            {
                max = dis[i][j];
            }
        }
        if (min > max)
        {
            min = max;
            hub = i;
        }
    }
    printf("%0.2f %0.2f\n",pts[hub].lat,pts[hub].lon);
    return 0;
}

 

Airline Hub

标签:

原文地址:http://www.cnblogs.com/tangxin-blog/p/5813896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!