Statistics

Problem Statement for "SwimmersDelight"

Problem Statement

You want to cross a river 10 feet wide and there are 2 stones in the water you can jump on. A few jumps are needed, but your only concern is the longest one. This is obviously the most problematic, so you wish to choose a path that makes this jump as small as possible.

The length of a jump between two stones of coordinates (x1,y1) and (x2,y2) is defined as the Euclidian distance:
  sqrt((x1 - x2) * (x1 - x2)  +  (y1 - y2) * (y1 - y2))

You will be given a int[] x and a int[] y with exactly 2 elements each, representing the coordinates of the stones: (x[i],y[i]) is the location of the i-th stone. The edge of the shore on which you initially stand has an x-value of 0 and could take any y-value. Thus, the minimal distance between the shore and the first stone you jump on is the x-value in the location of that stone. The edge of the other shore has an x-value of 10 and could take any y-value as well.

Return the distance of the longest jump you need to make, rounded to the nearest integer.

Definition

Class:
SwimmersDelight
Method:
longestJump
Parameters:
int[], int[]
Returns:
int
Method signature:
int longestJump(int[] x, int[] y)
(be sure your method is public)

Notes

  • You may jump on the 2 stones in any order, or just on one stone.

Constraints

  • x and y will each contain 2 elements.
  • All values in x are between 1 and 9, inclusive.
  • All values in y are between 0 and 10, inclusive.
  • The two stones are not in the same location.
  • No actual distance will be more than 1e-4 close to some integer + 0.5.

Examples

  1. {3,7}

    {5,5}

    Returns: 4

    The three stones are arranged in a line, so the strategy is quite simple here: you first jump on the stone at (3,5), then on the stone at (7,5) and you finally reach the other shore at (10,5). The longest jump has a length of 4 feet: from (3,5) to (7,5). If you like to play around, you can follow the path (0,5) - (7,5) - (3,5) - (10,5), but this is not optimal since you have to make a jump of 7 feet! Thus, the correct answer is 4.

  2. {3,6}

    {5,2}

    Returns: 4

    The path you should take is (0,5) - (3,5) - (6,2) - (10,2). Between (3,5) and (6,2) there is a distance of sqrt(3*3 + 3*3) = 4.2426. There are no jumps longer than this and because the answer is rounded to the nearest integer, you should return 4.

  3. {1,1}

    {4,6}

    Returns: 9

    If you can jump 9 feet at once, chances are you are also a good swimmer ...

  4. {3,8}

    {0,10}

    Returns: 7

    Only the stone at (3,0) is used in this case. The stone at (8,10) is more than 7 feet away from both the shore and the stone at (3,0).

  5. {4,2}

    {5,5}

    Returns: 6

    The river can be a good initiation in the triple-jump technique. But you can also skip the stone at (2,5), as you need to take a 6 feet jump anyway.

  6. {9,1}

    {0,6}

    Returns: 9

  7. {5,8}

    {4,10}

    Returns: 5

  8. {1,1}

    {9,6}

    Returns: 9

  9. {2,8}

    {7,5}

    Returns: 6

  10. {2,4}

    {9,3}

    Returns: 6

  11. {7,2}

    {6,2}

    Returns: 6

  12. {9,7}

    {7,10}

    Returns: 7

  13. {4,9}

    {8,0}

    Returns: 6

  14. {6,6}

    {1,7}

    Returns: 6

  15. {8,8}

    {0,3}

    Returns: 8

  16. {9,2}

    {7,2}

    Returns: 8

  17. {9,3}

    {7,0}

    Returns: 7

  18. {8,7}

    {8,0}

    Returns: 7

  19. {5,8}

    {8,4}

    Returns: 5

  20. {9,9}

    {1,2}

    Returns: 9

  21. {6,9}

    {1,7}

    Returns: 6

  22. {2,4}

    {1,0}

    Returns: 6

  23. {2,4}

    {4,2}

    Returns: 6

  24. {8,4}

    {7,4}

    Returns: 5

  25. {9,7}

    {2,4}

    Returns: 7

  26. {9,5}

    {1,4}

    Returns: 5

  27. {1,9}

    {3,3}

    Returns: 8

  28. {5,3}

    {4,2}

    Returns: 5

  29. {2,2}

    {3,6}

    Returns: 8

  30. {4,5}

    {3,8}

    Returns: 5

  31. {2,8}

    {3,3}

    Returns: 6

  32. {1,4}

    {0,2}

    Returns: 6

  33. {5,8}

    {8,4}

    Returns: 5

  34. {2,1}

    {10,1}

    Returns: 8

  35. {4,6}

    {5,3}

    Returns: 4

  36. {9,6}

    {4,3}

    Returns: 6

  37. {3,5}

    {9,4}

    Returns: 5

  38. {8,5}

    {8,1}

    Returns: 5

  39. {8,1}

    {1,10}

    Returns: 8

  40. {7,2}

    {9,2}

    Returns: 7

  41. {6,6}

    {6,1}

    Returns: 6

  42. {6,6}

    {0,3}

    Returns: 6

  43. {5,3}

    {7,3}

    Returns: 5

  44. {7,7}

    {0,7}

    Returns: 7

  45. {3,4}

    {3,4}

    Returns: 6

  46. {2,9}

    {2,2}

    Returns: 7

  47. {1,6}

    {10,3}

    Returns: 6

  48. {4,5}

    {2,8}

    Returns: 5

  49. {8,9}

    {3,4}

    Returns: 8

  50. {5,8}

    {3,10}

    Returns: 5

  51. {3,2}

    {4,7}

    Returns: 7

  52. {3,3}

    {6,10}

    Returns: 7

  53. {2,8}

    {1,7}

    Returns: 8

  54. {1,5}

    {2,7}

    Returns: 5

  55. {3,8}

    {9,10}

    Returns: 5

  56. {1,9}

    {8,5}

    Returns: 9

  57. {6,9}

    {2,1}

    Returns: 6

  58. {7,7}

    {5,7}

    Returns: 7

  59. {1,4}

    {5,3}

    Returns: 6

  60. {3,4}

    {6,10}

    Returns: 6

  61. {8,4}

    {10,1}

    Returns: 6

  62. {1,4}

    {5,3}

    Returns: 6

  63. {7,1}

    {2,1}

    Returns: 6

  64. {8,3}

    {7,7}

    Returns: 5

  65. {5,2}

    {5,8}

    Returns: 5

  66. {7,9}

    {9,2}

    Returns: 7

  67. {7,9}

    {10,2}

    Returns: 7

  68. {6,3}

    {2,1}

    Returns: 4

  69. {1,9}

    {4,7}

    Returns: 9

  70. {1,1}

    {8,3}

    Returns: 9

  71. {5,8}

    {6,8}

    Returns: 5

  72. {8,4}

    {2,8}

    Returns: 6

  73. {8,4}

    {7,0}

    Returns: 6

  74. {6,6}

    {9,5}

    Returns: 6

  75. {2,9}

    {10,1}

    Returns: 8

  76. {2,9}

    {0,5}

    Returns: 8

  77. {2,9}

    {7,1}

    Returns: 8

  78. {5,5}

    {6,2}

    Returns: 5

  79. {7,4}

    {3,1}

    Returns: 4

  80. {8,1}

    {4,8}

    Returns: 8

  81. {2,1}

    {0,5}

    Returns: 8

  82. {8,1}

    {6,3}

    Returns: 8

  83. {4,5}

    {4,10}

    Returns: 5

  84. {8,2}

    {1,8}

    Returns: 8

  85. {4,9}

    {3,9}

    Returns: 6

  86. {4,4}

    {5,8}

    Returns: 6

  87. {1,4}

    {10,2}

    Returns: 6

  88. {8,4}

    {3,7}

    Returns: 6

  89. {8,5}

    {10,6}

    Returns: 5

  90. {6,1}

    {6,2}

    Returns: 6

  91. {4,4}

    {1,7}

    Returns: 6

  92. {7,6}

    {0,2}

    Returns: 6

  93. {2,9}

    {4,1}

    Returns: 8

  94. {7,4}

    {10,6}

    Returns: 5

  95. {2,7}

    {9,7}

    Returns: 5

  96. {8,9}

    {6,9}

    Returns: 8

  97. {6,6}

    {4,9}

    Returns: 6

  98. {3, 8 }

    {0, 10 }

    Returns: 7

  99. {2, 7 }

    {10, 0 }

    Returns: 7

  100. {5, 5 }

    {1, 9 }

    Returns: 5

  101. {1, 6 }

    {1, 4 }

    Returns: 6

  102. {3, 5 }

    {0, 9 }

    Returns: 5

  103. {7, 8 }

    {1, 9 }

    Returns: 7

  104. {1, 7 }

    {1, 4 }

    Returns: 7

  105. {5, 1 }

    {10, 0 }

    Returns: 5

  106. {1, 3 }

    {0, 10 }

    Returns: 7

  107. {7, 3 }

    {0, 10 }

    Returns: 7

  108. {1, 5 }

    {0, 10 }

    Returns: 5

  109. {7, 3 }

    {0, 0 }

    Returns: 4

  110. {1, 9 }

    {1, 9 }

    Returns: 9

  111. {1, 8 }

    {0, 0 }

    Returns: 7

  112. {8, 1 }

    {1, 10 }

    Returns: 8

  113. {6, 3 }

    {1, 1 }

    Returns: 4

  114. {2, 8 }

    {4, 6 }

    Returns: 6

  115. {9, 1 }

    {5, 5 }

    Returns: 8

  116. {9, 8 }

    {5, 5 }

    Returns: 8

  117. {1, 5 }

    {1, 10 }

    Returns: 5

  118. {8, 2 }

    {3, 3 }

    Returns: 6

  119. {8, 9 }

    {0, 9 }

    Returns: 8

  120. {4, 8 }

    {8, 4 }

    Returns: 6

  121. {3, 9 }

    {5, 2 }

    Returns: 7

  122. {8, 6 }

    {5, 5 }

    Returns: 6

  123. {3, 5 }

    {7, 1 }

    Returns: 5

  124. {1, 8 }

    {0, 10 }

    Returns: 8

  125. {5, 5 }

    {0, 10 }

    Returns: 5


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: