BOJ1018 -- Airline Hub

Airline HubTime Limit: 1000MS  Memory Limit: 65536K

Description
World Wide Flyer has landing rights at several airports throughout the world. They wish to place their central hub at the airport that minimizes the maximum direct flying distance from the hub to any other airport in the world. 

Input
Input consists of a line containing n <= 1000, the number of airports. n lines follow, each giving the latitude (between -90 and +90 degrees) and longitude (between -180 and +180 degrees) of an airport.


Output
To two decimal places, give the latitude and longitude of the airport that best serves as a hub. If there are several any one will do. 


Sample Input

3
3.2 -15.0
20.1 -175
-30.2 10


Sample Output

3.20 -15.00


Source
Waterloo local 2000.01.29

 

解:

一首水题,主要是要懂球面的距离计算。

#include <iostream> #include <stdio.h> #include <math.h> using namespace std; typedef struct airport{ double x; double y; }A; double distance(double x1, double y1, double x2, double y2) { double n1 = x1 - x2; double n2 = y1 - y2; return sqrt(n1*n1 + n2*n2); } A a[1010]; double d[1010][1010]; int main() { int n, minNum, tempNum; double min = 0.0, temp = 0.0; int count = 0; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = 0.0; for (int i = 0; i < n; i++){ cin >> a[i].x >> a[i].y; } for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++){ d[j][i] = d[i][j] = distance(a[i].x, a[i].y, a[j].x, a[j].y); } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++) printf("%f/t", d[i][j]); cout << endl; } for (int i = 0; i < n; i++) min += d[0][i]; minNum = 0; cout << min << endl; for (int i = 1; i < n; i++){ temp = 0.0; for (int j = 0; j < n; j++) temp += d[i][j]; cout << temp << endl; if (min > temp){ minNum = i; min = temp; } } printf("%.2f %.2f/n", a[minNum].x, a[minNum].y); system("pause"); return 0; }

 

 

你可能感兴趣的:(BOJ1018 -- Airline Hub)