Statistics

Problem Statement for "GardenHose"

Problem Statement

Our garden is a square containing plants in n rows and n columns, a total of n*n plants. The distance between plants within a row is rowDist and between plants within a column is colDist.

I want to water the garden without getting my shoes muddy. That requires that I stand outside the garden, never closer than where the next row or column of the garden would be if it were enlarged. The hose can water plants that are hoseDist or less away from where I am standing. (Of course, I can move around and water from various locations.)

Create a class GardenHose that contains the method countDead that takes n, rowDist, colDist, and hoseDist as inputs and returns the number of plants that cannot be watered.

Definition

Class:
GardenHose
Method:
countDead
Parameters:
int, int, int, int
Returns:
int
Method signature:
int countDead(int n, int rowDist, int colDist, int hoseDist)
(be sure your method is public)

Constraints

  • n is between 1 and 50 inclusive
  • rowDist is between 1 and 50 inclusive
  • colDist is between 1 and 50 inclusive
  • hoseDist is between 1 and 10,000 inclusive

Examples

  1. 3

    2

    1

    2

    Returns: 0

    In the picture below, each plant is shown with a P, and the closest spots where I can stand without getting muddy shoes are shown with o. Even the center plant can be watered by standing at the end of its column. 0 1 2 3 4 5 6 7 8 0 ooooooooooooooooooooooooo o | | | | | | | o 1 o--+--P--+--P--+--P--+--o o | | | | | | | o 2 o--+--P--+--P--+--P--+--o o | | | | | | | o 3 o--+--P--+--P--+--P--+--o o | | | | | | | o 4 ooooooooooooooooooooooooo

  2. 3

    2

    1

    1

    Returns: 3

    (Same picture) Now the hose cannot reach any of the plants in the middle row.

  3. 4

    50

    2

    2

    Returns: 8

  4. 4

    50

    2

    4

    Returns: 0

  5. 4

    3

    2

    3

    Returns: 4

  6. 50

    50

    50

    1250

    Returns: 0

  7. 50

    50

    50

    1249

    Returns: 4

  8. 50

    49

    50

    1249

    Returns: 0

  9. 49

    50

    50

    1249

    Returns: 1

  10. 6

    2

    5

    5

    Returns: 8

  11. 6

    2

    5

    3

    Returns: 24

  12. 50

    50

    50

    49

    Returns: 2500

  13. 1

    2

    2

    1

    Returns: 1

  14. 6

    2

    5

    5

    Returns: 8

  15. 3

    2

    1

    1

    Returns: 3

  16. 50

    50

    50

    49

    Returns: 2500

  17. 1

    1

    1

    10000

    Returns: 0

  18. 2

    2

    2

    9000

    Returns: 0

  19. 1

    1

    1

    10

    Returns: 0

  20. 3

    2

    1

    2

    Returns: 0

  21. 2

    2

    2

    6000

    Returns: 0

  22. 5

    5

    5

    1

    Returns: 25

  23. 10

    1

    1

    20

    Returns: 0

  24. 5

    1

    1

    2

    Returns: 1

  25. 3

    3

    3

    50

    Returns: 0

  26. 3

    2

    1

    20

    Returns: 0

  27. 3

    2

    2

    5

    Returns: 0

  28. 6

    2

    5

    300

    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: