Statistics

Problem Statement for "Taxi"

Problem Statement

The "taxicab distance" between two points in space is defined to be the distance that would need to be travelled to get from one to the other using segments that are parallel to the axes. This is generally longer than the (straight-line) distance between the two points.

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

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

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

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

    5

    5

    Returns: 5.0

  5. 4

    4

    7

    Returns: 5.0

  6. 19

    13

    0

    Returns: 0.0

  7. 1

    20

    21

    Returns: 20.024984394500787

  8. 48

    1

    7

    Returns: 7.0

  9. 12

    12

    17

    Returns: 13.0

  10. 4

    12

    17

    Returns: -1.0

  11. 4

    12

    16

    Returns: 12.649110640673518

  12. 976421

    976421

    1000000

    Returns: 976705.6560100387

  13. 1000000

    22

    24

    Returns: 24.0

  14. 909

    3292

    4044

    Returns: 3376.798483771278

  15. 7968

    9804

    5140

    Returns: 5140.0

  16. 276

    6051

    3892

    Returns: 3892.0

  17. 3691

    1295

    1245

    Returns: 1245.0

  18. 5679

    7879

    4387

    Returns: 4387.0

  19. 5256

    7198

    4869

    Returns: 4869.0

  20. 5557

    7452

    2405

    Returns: 2405.0

  21. 2982

    4845

    3820

    Returns: 3820.0

  22. 8648

    4609

    6189

    Returns: 6189.0

  23. 5042

    1084

    336

    Returns: 336.0

  24. 1003

    3822

    2088

    Returns: 2088.0

  25. 9055

    2401

    3352

    Returns: 3352.0

  26. 9777

    9637

    12790

    Returns: 10230.733013816753

  27. 2752

    2185

    3273

    Returns: 2800.8828965167395

  28. 7268

    255

    3577

    Returns: 3577.0

  29. 976421

    976421

    1000000

    Returns: 976705.6560100387

  30. 999990

    10

    27

    Returns: 27.0

  31. 10

    200

    50

    Returns: 50.0

  32. 4

    4

    8

    Returns: 5.656854249492381

  33. 1000000

    1000000

    999999

    Returns: 999999.0

  34. 999990

    10

    999990

    Returns: 999990.0

  35. 10

    3

    24

    Returns: -1.0

  36. 10

    3

    7

    Returns: 7.0

  37. 7

    10

    13

    Returns: 10.44030650891055

  38. 976421

    976422

    1000000

    Returns: 976706.6315777733

  39. 3

    10

    4

    Returns: 4.0

  40. 10

    10

    1

    Returns: 1.0

  41. 10

    3

    2

    Returns: 2.0

  42. 6

    1

    5

    Returns: 5.0

  43. 10

    9

    6

    Returns: 6.0

  44. 3

    4

    7

    Returns: 5.0

  45. 10

    3

    3

    Returns: 3.0

  46. 4

    4

    3

    Returns: 3.0

  47. 7

    2

    5

    Returns: 5.0

  48. 490000

    490000

    1000000

    Returns: -1.0

  49. 100

    100

    5

    Returns: 5.0

  50. 499999

    499999

    999998

    Returns: 707105.3669729851

  51. 1

    7

    5

    Returns: 5.0

  52. 100

    150

    4

    Returns: 4.0

  53. 5

    10

    13

    Returns: 10.44030650891055

  54. 2

    2

    4

    Returns: 2.8284271247461903

  55. 1000000

    1000000

    888888

    Returns: 888888.0

  56. 1

    1

    2

    Returns: 1.4142135623730951

  57. 3

    3

    6

    Returns: 4.242640687119285

  58. 10

    7

    13

    Returns: 10.44030650891055

  59. 4

    2

    3

    Returns: 3.0

  60. 5

    5

    10

    Returns: 7.0710678118654755

  61. 1

    6

    5

    Returns: 5.0


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: