zoj 1868 || UVA 10316 Airline Hub

来源:互联网 发布:亚马逊物流网络 编辑:程序博客网 时间:2024/04/29 13:33

这题卡精度啊。。伤不起。看来以后还是不要那么懒了。。

求在哪个飞机场建造个HUB使得所有飞机场到这个HUB最长距离最短。给的是大地坐标。
N才1000,枚举下就好了。
比较圆心角就好了,因为地球半径是一样的。
#include <set>#include <map>#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>#define MID(x,y) ( ( x + y ) >> 1 )#define L(x) ( x << 1 )#define R(x) ( x << 1 | 1 )#define BUG puts("here!!!")using namespace std;const int MAX = 1010;const double pi = acos(-1.0);const double inf = 1e30;struct point { double lng, lat, x,y;};point p[MAX];const double eps = 1e-6;bool dy(double x,double y){return x > y + eps;}// x > y bool xy(double x,double y){return x < y - eps;}// x < y bool dyd(double x,double y){ return x > y - eps;}// x >= y bool xyd(double x,double y){return x < y + eps;} // x <= y bool dd(double x,double y) {return fabs( x - y ) < eps;}  // x == ydouble torad(double x){return x*pi/180;}double angle_3d(double lng1, double lat1, double lng2, double lat2)  {           //经度,纬度,经度,纬度       return acos(cos(lat1)*cos(lat2)*cos(lng1 - lng2) + sin(lat1)*sin(lat2));  }  double dis(int k,int i){double ang = angle_3d(p[i].lng, p[i].lat, p[k].lng, p[k].lat);return ang;}int solve(int n){double mmin = inf;int t;for(int i=0; i<n; i++){double mmax = 0;for(int k=0; k<n; k++){if( k == i ) continue;if( dy(dis(k,i), mmax) )mmax = dis(k,i);}if( xyd(mmax, mmin) ){mmin = mmax;t = i;}}return t;}int main(){int n;double x, y;while( ~scanf("%d", &n) ){for(int i=0; i<n; i++){scanf("%lf %lf", &x, &y);p[i].lat = torad(x);p[i].lng = torad(y);p[i].x = x; p[i].y = y;}int ans = solve(n);printf("%.2lf %.2lf\n", p[ans].x, p[ans].y);}return 0;}


原创粉丝点击