【POJ2587】Airline Hub(经纬度求距离)

本文介绍了一道算法题的解决思路,该题要求找出在一组经纬度坐标中,找到一个点使得它到其它所有点的最大距离最小。文章提供了一个C++实现方案,并使用了球面三角学来计算地球上两点之间的距离。

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

记录一个菜逼的成长。。

题目链接
题目大意:
给你n个点的经纬度,求一个点到其他点的距离的最大值里是最小。

具体解释
需要用到经纬度求距离的公式。
当个模板好了。

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int INF = 0x3f3f3f3f;
const double pi = acos(-1);
const int maxn = 1000 + 10;
struct node{
    double x,y;
}a[maxn];
double cal(double d)
{
    return d * pi / 180.0;
}
int main()
{
    int n;
    while(~scanf("%d",&n)){
        for( int i = 0; i < n; i++ ){
            scanf("%lf%lf",&a[i].x,&a[i].y);
        }
        double dis = INF * 100;
        double x,y;
        for( int i = 0; i < n; i++ ){
            double tmp = 0;
            for( int j = 0; j < n; j++ ){
                if(i != j){
                    double t1 = cal(a[i].x),t2 = cal(a[j].x);
                    double c = t1 - t2;
                    double b = cal(a[i].y) - cal(a[j].y);
                    double s = 2 * asin(sqrt(pow(sin(c/2),2) + cos(t1) * cos(t2) * pow(sin(b/2),2)));
                    s = s * 6378.137;
                    tmp = max(tmp,s);
                }
            }
            if(tmp < dis){
                dis = tmp;
                x = a[i].x;
                y = a[i].y;
            }
        }
        printf("%.2f %.2f\n",x,y);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值