Problem Statement
Definition
- Class:
- WaterBot
- Method:
- minTime
- Parameters:
- String[], int
- Returns:
- int
- Method signature:
- int minTime(String[] garden, int carryLimit)
- (be sure your method is public)
Notes
- Initially, the robot is holding zero units of water.
- The robot may not step out of the garden at any time.
Constraints
- garden will contain between 1 and 50 elements, inclusive.
- Each element in garden will contain between 1 and 50 characters, inclusive.
- All elements in garden will be of the same size.
- Each element in garden may only contain the following characters: 'W', 'R', '.', '1', '2', '3', '4', '5' (quotes for clarity).
- garden will contain exactly one occurrence of 'R' and 'W'.
- garden will contain between 0 and 4 digits, inclusive.
- carryLimit will be between 1 and 5, inclusive.
Examples
{"..................................................", ".5..............................................5.", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "........................W.........................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".5..............................................5.", "........................R........................."}
5
Returns: 378
The worst possible case.
{"..................................................", ".5..............................................5.", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "........................W.........................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".5..............................................5.", "........................R........................."}
1
Returns: 1818
Same case as the first, but smaller carryLimit. The return value is larger, but there are less states - so this case runs a bit faster.
{"5....", ".....", ".....", ".....", "...RW"}
5
Returns: 16
The robot begins its journey next to the well. It takes 5 units of time to collect 5 units of water. Then, it takes 6 units of time to move to the only plant that needs watering. At last, the robot will water the plant for 5 units of time. The total time required is 16 units.
{"3.2..", ".....", ".....", "....R", "....W"}
5
Returns: 16
Once again, the robot is next to the well. The most efficient schedule is to collect 5 units of water, then water both plants without returning to the well.
{"3.3..", ".....", ".....", "....R", "....W"}
3
Returns: 26
{"5.5..", ".....", ".....", "....R", "....W"}
5
Returns: 34
{"5.5.5", ".....", ".....", "....R", "....W"}
5
Returns: 48
{".5555", ".....", ".....", "....R", "....W"}
3
Returns: 85
{".5555", ".....", ".....", "....R", "....W"}
2
Returns: 107
{"R.......", "..5.5...", ".5......", "..5.....", "........", ".......W"}
5
Returns: 92
{"R.....55", "......55", "........", "........", "........", ".......W"}
2
Returns: -1
The robot cannot reach the top-right plant without stepping on at least one other plant.
{"R.......", "........", "....5...", "...5W5..", "....5...", "........"}
4
Returns: -1
The robot cannot get any water from the well.
{"R.......", "....5...", "........", "....W...", "........", "........"}
5
Returns: 16
{".1", ".2", ".3", ".4", "R.", "W."}
5
Returns: 28
{"R....", ".....", ".....", ".....", "....W"}
5
Returns: 0
There are no plants to water here.
{"..................................................", ".5..............................................5.", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "........................W.........................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".5..............................................5.", "........................R........................."}
2
Returns: 1008
same as tests 0 and 1, but different carryLimit
{"..................................................", ".5..............................................5.", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "........................W.........................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".5..............................................5.", "........................R........................."}
3
Returns: 738
{"..................................................", ".5..............................................5.", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "........................W.........................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".5..............................................5.", "........................R........................."}
4
Returns: 596
{"1......1", "........", "...W....", "...R....", "........", "1......5"}
4
Returns: 41
A miniature version of test 17. I haven't figured out a path that takes 41 time units yet...
{".......1", "........", "........", "....R...", "W.......", ".....4..", "....3...", "..3....."}
2
Returns: 71
{".......1", "........", "........", "....R...", "W.......", ".....4..", "....3...", "..3....."}
{ ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", "........5........................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", "............4....................................", ".................................................", ".................................................", "............................................W....", ".................................................", ".................................................", ".................................................", ".............5...................................", ".................................................", ".................................................", ".................................................", "..............................5..................", ".................................................", ".................................................", ".................................................", ".................................................", "..............................................R..", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", ".................................................", "................................................." }
4
Returns: 365
{ "W.................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".................................................5", ".................................................5", "..............................................55.R" }
1
Returns: 3802