Problem Statement
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
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
3
2
1
1
Returns: 3
(Same picture) Now the hose cannot reach any of the plants in the middle row.
4
50
2
2
Returns: 8
4
50
2
4
Returns: 0
4
3
2
3
Returns: 4
50
50
50
1250
Returns: 0
50
50
50
1249
Returns: 4
50
49
50
1249
Returns: 0
49
50
50
1249
Returns: 1
6
2
5
5
Returns: 8
6
2
5
3
Returns: 24
50
50
50
49
Returns: 2500
1
2
2
1
Returns: 1
6
2
5
5
Returns: 8
3
2
1
1
Returns: 3
50
50
50
49
Returns: 2500
1
1
1
10000
Returns: 0
2
2
2
9000
Returns: 0
1
1
1
10
Returns: 0
3
2
1
2
Returns: 0
2
2
2
6000
Returns: 0
5
5
5
1
Returns: 25
10
1
1
20
Returns: 0
5
1
1
2
Returns: 1
3
3
3
50
Returns: 0
3
2
1
20
Returns: 0
3
2
2
5
Returns: 0
6
2
5
300
Returns: 0