Problem Statement
Our problem is where to locate our TV station's broadcasting tower. We know
the locations of the towns we should serve. Fortunately, we are located on the
flat, flat prairie, so the only issue is where to locate the tower to minimize the
broadcast radius that includes all the towns.
We have int[] x and int[] y giving the locations of the towns; the i-th elements of x and y give the coordinates of the i-th town. Create a class TVTower that contains a method minRadius that is given x and y, and returns the minimum broadcast radius that can reach all the towns. The tower's location is NOT restricted to integer coordinates.
Definition
- Class:
- TVTower
- Method:
- minRadius
- Parameters:
- int[], int[]
- Returns:
- double
- Method signature:
- double minRadius(int[] x, int[] y)
- (be sure your method is public)
Notes
- If the return has either a relative or absolute error less than 1.0E-9 it is acceptable.
Constraints
- x will contain between 1 and 50 elements inclusive.
- y will contain the same number of elements as x.
- Each element in x and y will be between -1000 and 1000 inclusive.
Examples
{1, 0, -1, 0}{0, 1, 0, -1}Returns: 1.0
By symmetry we should locate the tower at the origin, which is in the center of the diamond formed by these 4 towns.{3}{299}Returns: 0.0
Locate the tower right in the town.{5, 3, -4, 2}{0, 4, 3, 2}Returns: 4.743416490252569