FoxBomb
SRM 539 · 2011-11-22 · by ir5
Problem Statement
Ciel can place bombs onto floor cells of the field. When a bomb explodes, its blast spreads to four direction - up, down, left and right. In each of the four directions the blast only stops when it hits the wall. When a cell gets hit by a blast, its color turns to red. The purpose of the game is to color all floor cells red by placing as few bombs as possible.
You are given a
In this problem, there is an additional constraint: the floor cells form a tree. A more formal specification follows: We say that two cells are adjacent when they share an edge. A path from cell A to cell B is a sequence of distinct cells such that the first cell in the sequence is cell A, the last cell is B, and each pair of consecutive cells in the sequence is adjacent. A floor-only path is a path such that all cells in it, including A and B, are floor cells. The test data for this task has the following property: For each pair of floor cells in the grid, there is exactly one floor-only path from one of them to the other.
Constraints
- grid will contain between 1 and 50 elements, inclusive.
- Each element of grid will contain between 1 and 50 characters, inclusive.
- All elements of grid will contain the same number of characters.
- Each character of grid will be either '#' or '.'.
- grid will contain at least one '.' character.
- Floor cells of grid will form a tree. See the statement for formal constraints.
{"#..."
,"..##"
,"#.##"}
Returns: 2
In this case, there are multiple optimal solutions. One of the optimal solution is shown below. Here, 'B' represents a cell to which Ciel should place a bomb. #.B. .B## #.##
{".#.#.#."
,"......."
,".#.#.#."}
Returns: 4
One optimal solution is shown below. .#.#.#. B.B.B.B .#.#.#.
{"######################################"
,"######################################"
,"###.....................##############"
,"###.###################.###....#...###"
,"###.###################.###.######.###"
,"###.###################.###.######.###"
,"###.###################.###.######.###"
,"###.###################.###.######.###"
,"###.###################.###.######.###"
,"###.........####........###.######.###"
,"###########.###########.###........###"
,"###########.###########.##########.###"
,"###########.###########.##########.###"
,"###########.###########.##########.###"
,"###########.###########.##########.###"
,"##..........##..........##########.###"
,"#######################............###"
,"######################################"}
Returns: 9
{".#."
,"..."
,"#.#"
,"..."
,".#."}
Returns: 5
{"."}
Returns: 1
Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FoxBomb with a public method int getMinimumCost(vector<string> grid) · 90 test cases · 2 s / 256 MB per case