# Problem B - Airline Hub

Problem B - Airline Hub

## Problem B - Airline Hub

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 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.

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.

``````3
3.2 -15.0
20.1 -175
-30.2 10
``````

``````3.20 -15.00
``````

``````#include <stdio.h>
#include <math.h>

int n;
double x, y, r;
int top;

int possible = 1;
double ne = 1000, nw = 1000;

main(){
int i,j,k;
scanf("%d",&n);
for (i=0;i<n;i++) scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
for (i=0;i<n;i++) if (y[i]+r[i] > 1000) visit(i);
if (possible) printf(
"Bill enters at (0.00, %0.2lf) and leaves at (1000.00, %0.2lf).\n",nw,ne);
else printf("Bill will be bitten.\n");
}

visit(int i){
int j,k;
double yy;
if (top[i]++) return;

for (j=0;j<n;j++) {
if (hypot(x[j]-x[i],y[j]-y[i]) < r[i]+r[j]) visit(j);
}
if (y[i]-r[i] < 0) possible = 0;
if (x[i]-r[i] < 0) {
yy = y[i] - sqrt(r[i]*r[i] - x[i]*x[i]);
if (yy < nw) nw = yy;
}
if (x[i]+r[i] > 1000) {
yy = y[i] - sqrt(r[i]*r[i] - (1000-x[i])*(1000-x[i]));
if (yy < ne) ne = yy;
}
}
``````

``````#include <stdio.h>
#include <math.h>

int n;
double x, y, r;
int top;

int possible = 1;
double ne = 1000, nw = 1000;

main(){
int i,j,k;
scanf("%d",&n);
for (i=0;i<n;i++) scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
for (i=0;i<n;i++) if (y[i]+r[i] > 1000) visit(i);
if (possible) printf(
"Bill enters at (0.00, %0.2lf) and leaves at (1000.00, %0.2lf).\n",nw,ne);
else printf("Bill will be bitten.\n");
}

visit(int i){
int j,k;
double yy;
if (top[i]++) return;

for (j=0;j<n;j++) {
if (hypot(x[j]-x[i],y[j]-y[i]) < r[i]+r[j]) visit(j);
}
if (y[i]-r[i] < 0) possible = 0;
if (x[i]-r[i] < 0) {
yy = y[i] - sqrt(r[i]*r[i] - x[i]*x[i]);
if (yy < nw) nw = yy;
}
if (x[i]+r[i] > 1000) {
yy = y[i] - sqrt(r[i]*r[i] - (1000-x[i])*(1000-x[i]));
if (yy < ne) ne = yy;
}
}
``````