Problem Statement
We know the taxicab distance between two points. We want to know the maximum straight-line distance between them if they lie in the rectangular region { (x,y) | 0<=x<=maxX, 0<=y<=maxY }. Create a class Taxi that contains a method maxDis that is given maxX, maxY, and taxiDis and that returns the largest possible straight-line distance between the two points. If no two points within the given region have the given taxicab distance, return -1.0.
Definition
- Class:
- Taxi
- Method:
- maxDis
- Parameters:
- int, int, int
- Returns:
- double
- Method signature:
- double maxDis(int maxX, int maxY, int taxiDis)
- (be sure your method is public)
Notes
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- maxX and maxY are both between 1 and 1,000,000, inclusive.
- taxiDis is between 0 and 1,000,000, inclusive.
Examples
10
3
3
Returns: 3.0
The two points could lie in a straight line parallel to one of the axes. Then the straight-line distance would be the same as the taxicab distance.10
3
24
Returns: -1.0
No two points with 0<=x<=10, 0<=y<=3, have a taxicab distance between them that is as big as 24.7
10
13
Returns: 10.44030650891055
(5,0) and (2,10) are two points in this region whose taxicab distance is |2-5| + |10-0| = 13 and whose straight-line distance is sqrt(3*3 + 10*10) = sqrt(109).4
4
7
Returns: 5.0
976421
976421
1000000
Returns: 976705.6560100387