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).
5
5
5
Returns: 5.0
4
4
7
Returns: 5.0
19
13
0
Returns: 0.0
1
20
21
Returns: 20.024984394500787
48
1
7
Returns: 7.0
12
12
17
Returns: 13.0
4
12
17
Returns: -1.0
4
12
16
Returns: 12.649110640673518
976421
976421
1000000
Returns: 976705.6560100387
1000000
22
24
Returns: 24.0
909
3292
4044
Returns: 3376.798483771278
7968
9804
5140
Returns: 5140.0
276
6051
3892
Returns: 3892.0
3691
1295
1245
Returns: 1245.0
5679
7879
4387
Returns: 4387.0
5256
7198
4869
Returns: 4869.0
5557
7452
2405
Returns: 2405.0
2982
4845
3820
Returns: 3820.0
8648
4609
6189
Returns: 6189.0
5042
1084
336
Returns: 336.0
1003
3822
2088
Returns: 2088.0
9055
2401
3352
Returns: 3352.0
9777
9637
12790
Returns: 10230.733013816753
2752
2185
3273
Returns: 2800.8828965167395
7268
255
3577
Returns: 3577.0
976421
976421
1000000
Returns: 976705.6560100387
999990
10
27
Returns: 27.0
10
200
50
Returns: 50.0
4
4
8
Returns: 5.656854249492381
1000000
1000000
999999
Returns: 999999.0
999990
10
999990
Returns: 999990.0
10
3
24
Returns: -1.0
10
3
7
Returns: 7.0
7
10
13
Returns: 10.44030650891055
976421
976422
1000000
Returns: 976706.6315777733
3
10
4
Returns: 4.0
10
10
1
Returns: 1.0
10
3
2
Returns: 2.0
6
1
5
Returns: 5.0
10
9
6
Returns: 6.0
3
4
7
Returns: 5.0
10
3
3
Returns: 3.0
4
4
3
Returns: 3.0
7
2
5
Returns: 5.0
490000
490000
1000000
Returns: -1.0
100
100
5
Returns: 5.0
499999
499999
999998
Returns: 707105.3669729851
1
7
5
Returns: 5.0
100
150
4
Returns: 4.0
5
10
13
Returns: 10.44030650891055
2
2
4
Returns: 2.8284271247461903
1000000
1000000
888888
Returns: 888888.0
1
1
2
Returns: 1.4142135623730951
3
3
6
Returns: 4.242640687119285
10
7
13
Returns: 10.44030650891055
4
2
3
Returns: 3.0
5
5
10
Returns: 7.0710678118654755
1
6
5
Returns: 5.0