Problem Statement
For instance, the board shown to the left is a valid board, while the one on the right is not because there is a mine adjacent to a cell that contains a 0 (here, '*' represents a mine).
11000 02210 *2921 1**** 23**1 03332 *2251 *1000
You have already written a subroutine that has filled in the first few randomly chosen cells of the game board, which is given as a
Since you want the game to be as challenging as possible, you wish to find the maximal number of mines that the board may be filled with such that the resulting board configuration is valid. Note that a mine configuration is valid if and only if the number of mines surrounding each original non-blank cell is at most the number inside that cell.
Definition
- Class:
- MinePut
- Method:
- getMines
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int getMines(String[] partialBoard)
- (be sure your method is public)
Notes
- You may not place a mine in a filled cell; only a blank one.
Constraints
- partialBoard will contain between 1 and 22 elements, inclusive.
- Each element of partialBoard will contain between 1 and 22 characters, inclusive.
- Each element of partialBoard will contain the same number of characters.
- partialBoard will contain at most 22 characters.
- Each element of partialBoard will contain only digits ('0'-'9') and '.' characters.
Examples
{ "0050", "0100", "0010", "3000"}
Returns: 0
It's impossible to place any mines.
{ ".100", "1100", "0000", "0000"}
Returns: 1
The only possible location for a mine is the upper left corner.
{ ".....", ".....", ".....", "....."}
Returns: 20
The entire board can be filled with mines.
{ "3.4..1", "2.21..", "999999"}
Returns: 3
{ "......................"}
Returns: 22
{ "....", ".99.", ".99.", "...."}
Returns: 12
{ "....", ".11.", ".11.", "...."}
Returns: 4
{ "2..2", "....", "....", "2..2"}
Returns: 8
{ "1110", "1.12", ".2.1", "1211"}
Returns: 2
{ "11.1", "1.22", "11.1", "0211"}
Returns: 2
{ "99999", "99999", "99999"}
Returns: 0
{ ".3..3", "..321", "112..", "..321"}
Returns: 4
{ "3223", "2..2", "2..2", "1..0"}
Returns: 3
{ "3223", "2..2", "2.02", "3223"}
Returns: 0
{ ".......", ".......", "......." }
Returns: 21
{ "...", "...", "...", "...", "...", "...", "..." }
Returns: 21
{ "...........", "..........." }
Returns: 22
{ "..", "..", "..", "..", "..", "..", "..", "..", "..", "..", ".." }
Returns: 22
{ "..", "..", "..", "..", "..", "..", "..", "5.", "..", "..", ".." }
Returns: 21
{ "...........", "....8......" }
Returns: 21
{ "...", "...", "9..", "...", "...", "...", "..." }
Returns: 20
{ "...", "...", "...", "...", ".7.", "...", "..." }
Returns: 19
{ ".653", ".5.4", "5.9.", "..5."}
Returns: 8
{ "..11.1", "11.1.1", "..111."}
Returns: 2
{ "01.2", "00..", "000.", "...."}
Returns: 0
{ "."}
Returns: 1
{ "9"}
Returns: 0
{ "..9.9", "11111"}
Returns: 2
{ "0"}
Returns: 0
{ ".000.", "11111", ".....", "00.00"}
Returns: 0
{"3333", "....", "3333", "....", "3333" }
Returns: 5
{".1.", "121", ".10" }
Returns: 2
{"3333", "....", "3333", "....", "3333" }
Returns: 5
{".1.", "121", ".10" }
Returns: 2