| <p> | |
| A top-secret algorithmic research facility has decided to up its security by hiring guards to keep watch over the premises. | |
| After all, they don't want anyone sneaking in and learning the answers to questions such as "does P = NP?" and | |
| "what are the solutions to the 2016 Facebook Hacker Cup problems?". | |
| </p> | |
| <p> | |
| When viewed from above, the facility can be modeled as a grid <strong>G</strong> with 2 rows and <strong>N</strong> columns. | |
| The <strong>j</strong>th cell in the <strong>i</strong>th row is either empty (represented by <strong>G<sub>i,j</sub></strong> = ".") | |
| or occupied by a building (<strong>G<sub>i,j</sub></strong> = "X"), and the grid includes at least one empty cell. | |
| </p> | |
| <p> | |
| Guards may be potentially stationed in any of the empty cells. A guard can see not only their own cell, but also all contiguous empty cells in each of the 4 compass directions | |
| (up, down, left, and right) until the edge of the grid or a building. For example, in the grid below, the guard ("G") can see every cell marked with an asterisk ("*"): | |
| </p> | |
| <pre> | |
| .*.X.X.. | |
| *G*****X | |
| </pre> | |
| <p> | |
| What is the minimum number of guards required such that every empty cell in the grid can be seen by at least one of them? | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of facilities that need guarding. | |
| For each facility, there is first a line containing the integer <strong>N</strong>. The next line contains the grid cells | |
| <strong>G<sub>1,1</sub></strong> to <strong>G<sub>1,N</sub></strong> in order. The third line contains the grid cells | |
| <strong>G<sub>2,1</sub></strong> to <strong>G<sub>2,N</sub></strong> in order. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <strong>i</strong>th facility, print a line containing "Case #<strong>i</strong>: " followed by | |
| the number of guards required to guard the facility. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 200 <br /> | |
| 1 ≤ <strong>N</strong> ≤ 1,000 <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the first case, one solution is to place three guards as follows: | |
| </p> | |
| <pre> | |
| .G.X.XG. | |
| ....G..X | |
| </pre> | |