Statistics

Problem Statement for "Tether"

Problem Statement

We have a goat. We want to tether him with a long rope to the only solid structure we have in our orchard, a cylindrical water tank with its round base sitting on the ground. We are worried that the goat will be able to get at our fruit trees and will destroy them.

The rope will be attached at the southernmost point on the water tank. The rope cannot pass through the water tank, so as the goat tries to reach some of our trees the rope may wrap part way around the circular base of the tank.

Create a class Tether that contains a method deadTrees that takes the length of the rope, the radius of the water tank, and the locations of our trees and returns the number of trees that the goat will be able to reach. The locations of our trees are given by int[] x and int[] y, the distances east and north respectively from the center of the tank.

Definition

Class:
Tether
Method:
deadTrees
Parameters:
int, int, int[], int[]
Returns:
int
Method signature:
int deadTrees(int rope, int radius, int[] x, int[] y)
(be sure your method is public)

Notes

  • x and y give the coordinates east and north of the tank's center
  • the goat will be tethered at the southernmost point on the tank, (0,-radius)
  • if the goat can just exactly reach a tree, count the tree as dead
  • the rope can not pass through the tank, but it is not impeded by trees (since they would have been eaten all the way down to the ground)
  • it has been verified that none of the allowed inputs can lead to significant rounding errors. (There are no attainable distances that are within 1E-10 of an integer, and are not exactly an integer).

Constraints

  • rope is between 1 and 300 inclusive
  • radius is between 1 and 300 inclusive
  • x contains between 1 and 50 elements
  • y contains the same number of elements as x
  • each element of x and y is between -300 and 300 inclusive
  • each location (xi,yi) is distinct from each other location
  • xi*xi + yi*yi > radius*radius for each element of x and y (so no trees are inside the tank)

Examples

  1. 30

    10

    {0,0,0}

    {-11,-12,11}

    Returns: 2

    The goat is tethered at (0,-10) and can easily reach the first two trees. If the tank were not in the way, the goat could get to the northern tree, but the distance is greater than 30 going around the tank.

  2. 30

    10

    {0,-11,-10,-10}

    {-30,0,14,15}

    Returns: 3

    The first tree can just be reached -- count it. The second tree is easily reached going clockwise around the tank. The third tree can be reached by going 1/4 of the way around the tank and then straight north, but the fourth tree is out of reach.

  3. 31

    10

    {0,-11,-10,-10}

    {-30,0,14,15}

    Returns: 4

    This is the same as the previous example but with the rope slightly longer.

  4. 30

    10

    {0,-11, 10,-10}

    {-30,0,14,15}

    Returns: 3

  5. 200

    100

    {100,100,100,100,-100,100}

    {1,-273,-274,42,42,43}

    Returns: 4

  6. 207

    27

    {202}

    {18}

    Returns: 0

  7. 208

    27

    {202}

    {18}

    Returns: 1

  8. 88

    1

    {44,-44,0}

    {75,75,-87}

    Returns: 3

  9. 289

    18

    {288}

    {6}

    Returns: 0

  10. 30

    7

    {7,8,9,10,11,12,13,14,15,16,-17,-18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56}}

    {7,7,8,9,10,11,12,13,14,15,16,-17,-18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55}

    Returns: 13

  11. 13

    3

    {5,-5,0}

    {-15,-15,-16}

    Returns: 3

  12. 12

    3

    {5,-5,0}

    {-15,-15,-16}

    Returns: 0

  13. 13

    6

    {12,-12,12,-12}

    {-1,-11,-11,-1}

    Returns: 2

  14. 140

    49

    {52,52,52,52,-43,48,201,200,199,-198,33,34,35,35,36,66,-67,68}

    {50,-51,52,-53,54,-55,56,-57,58,-59,60,-61,62,-63,64,-65,66,-67}

    Returns: 11

  15. 207

    27

    {-202}

    {18}

    Returns: 0

  16. 157

    27

    {-149}

    {22}

    Returns: 1

  17. 100

    100

    { 0 }

    { -150 }

    Returns: 1

  18. 4

    4

    { 5, 1, -3, 5, -4, 3, 2, 3, 5, 5, -3, 5, -2, -3, 3, -2, 2, 3, -2, -3, 4, 3, 4, -5, 1, -3, 2, 4, -1, -5, -5, -5, -5, -1, 5, 0, 1, 4, 5, 4, 5, -4, 5, -1, 4, 4, -4, 1, -4, 5 }

    { -5, 5, -3, 4, -2, -3, -5, -5, 5, -4, -5, -2, -4, 3, -4, 4, 5, 4, 5, -4, 3, 3, -1, 3, -5, 5, 4, 1, 4, -1, 0, 5, 4, -4, -1, -5, -4, 5, 0, -2, 1, 2, -3, 5, 2, -3, -5, 4, -1, 3 }

    Returns: 12

  19. 1

    1

    { 0 }

    { -2 }

    Returns: 1

  20. 20

    10

    { -40 }

    { -10 }

    Returns: 0

  21. 150

    100

    { 100 }

    { -1 }

    Returns: 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: