• UVa 10316


    题目:给出地球上的n个机场的经度和纬度,想在这里面确定一个HUB使得他到其他机场的最大距离最小。

    分析:计算几何、大地坐标系。因为数据不大直接枚举即可,比较时利用圆心角可以提高计算效率,并控制精度。

                利用公式可直接解得两点的空间圆心角:acos(cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2));

                因为又是大地坐标,所以再推一遍吧,推导过程如下:

                          

                如图,C,D为已知两点则有如下推导:            

                AB = r*cos(lat1);DE = r*cos(lat2);BE = r*sin(lat1) + r*sin(lat2);

                AD*AD = BE*BE + (AB-DE)*(AB-DE) = 2*r*r - 2*r*r*sin(lat1)*sin(lat2) - 2*r*r*cos(lat1)*cos(lat2);

                AC*AC = 2*AB*AB - 2*AB*AB*cos(lon1-lon2) = 2*r*r*cos(lat1)*cos(lat1)*(1-cos(lon1-lon2));

                DF*DF = 2*DE*DE - 2*DE*DE*cos(lon1-lon2) = 2*r*r*cos(lat2)*cos(lat2)*(1-cos(lon1-lon2));

                AC*DF = 2*r*r*cos(lat1)*cos(lat2)*(1-cos(lon1-lon2));

                由托勒密定理有 AC*DF + AD*AD = CD*CD 整理有:

                CD = r*sqrt(2-2*(cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2)));

                设圆心角为α则:

                cos(0.5*α) = 0.5*CD/r = sqrt(0.5-0.5*(cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2)));

                cos(0.5*α)*cos(0.5*α) = 0.5 - 0.5*(cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2));

                cosα = 1 - 2*cos(0.5*α)*cos(0.5*α) = cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2);

                圆心角为:acos(cos(lat1)*cos(lat2)*cos(lon1-lon2)+sin(lat1)*sin(lat2));

    注意:精度控制。

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    
    using namespace std;
    
    double dis[1005][1005];
    double lat[1005];
    double lon[1005];
    
    double dist( double l1, double d1, double l2, double d2 )
    {
    	double p = acos(-1.0);
    	l1 *= p/180.0; d1 *= p/180.0; 
    	l2 *= p/180.0; d2 *= p/180.0; 
    	return acos(cos(l1)*cos(l2)*cos(d1-d2)+sin(l1)*sin(l2));
    }
    
    int main()
    {
    	int n;
    	while ( ~scanf("%d",&n) ) {
    		for ( int i = 0 ; i < n ; ++ i )
    			scanf("%lf%lf",&lat[i],&lon[i]);
    		
    		for ( int i = 0 ; i < n ; ++ i )
    		for ( int j = i ; j < n ; ++ j )
    			dis[i][j] = dis[j][i] = dist( lat[i], lon[i], lat[j], lon[j] );
    		
    		double min = 1e20;
    		int    spa = 0;
    		for ( int i = 0 ; i < n ; ++ i ) {
    			double max = 0.0;
    			for ( int j = 0 ; j < n ; ++ j )
    				if ( max+1e-6 < dis[i][j] )
    					max = dis[i][j];
    			if ( min+1e-6 > max ) {
    				min = max;
    				spa = i;
    			}
    		}
    		
    		printf("%.2lf %.2lf
    ",lat[spa],lon[spa]);
    	}
    	return 0;
    }
    
  • 相关阅读:
    LDAP个人理解
    webpack-dev-middleware 与 webpack-hot-middlware
    RFC、EMCA-262、TC-39等名词
    贝塞尔曲线
    Async/await语法糖实现(Generator)
    Promise嵌套问题/async await执行顺序
    JS对象中,在原型链上找到属性后 最终将值拷贝给原对象 而不是引用
    三列布局中 float引发的一个问题-当“非float的元素”和“float的元素”在一起的时候,如果非float元素在先,那么float的元素将受到排斥。
    05-Linux系统编程-第02天(文件系统、目录操作、dup2)
    降低30%视频码率,窄带高清技术实现揭秘
  • 原文地址:https://www.cnblogs.com/riskyer/p/3369558.html
Copyright © 2020-2023  润新知