#P16486. [GKS 2014 #C] Minesweeper

    ID: 16471 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>搜索2014连通块Google Kick Start

[GKS 2014 #C] Minesweeper

题目描述

Minesweeper is a computer game that became popular in the 19801980s, and is still included in some versions of the Microsoft Windows operating system. This problem has a similar idea, but it does not assume you have played Minesweeper.

In this problem, you are playing a game on a grid of identical cells. The content of each cell is initially hidden. There are MM mines hidden in MM different cells of the grid. No other cells contain mines. You may click on any cell to reveal it. If the revealed cell contains a mine, then the game is over, and you lose. Otherwise, the revealed cell will contain a digit between 00 and 88, inclusive, which corresponds to the number of neighboring cells that contain mines. Two cells are neighbors if they share a corner or an edge. Additionally, if the revealed cell contains a 00, then all of the neighbors of the revealed cell are automatically revealed as well, recursively. When all the cells that don't contain mines have been revealed, the game ends, and you win.

For example, an initial configuration of the board may look like this ("*" denotes a mine, and 'c' is the first clicked cell):

*..*...**.
....*.....
..c..*....
........*.
..........

There are no mines adjacent to the clicked cell, so when it is revealed, it becomes a 00, and its 88 adjacent cells are revealed as well. This process continues, resulting in the following board:

*..*...**.
1112*.....
00012*....
00001111*.
00000001..

At this point, there are still un-revealed cells that do not contain mines (denoted by '.' characters), so the player has to click again in order to continue the game.

You want to win the game as quickly as possible. You want to find the minimum number of clicks to win the game. Given the size of the board (N×NN \times N), output such minimum number of clicks.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. First line of each test case contains one integer NN. NN lines strings with length NN follows containing '*' and '.', denotes the Minesweeper initial board.

输出格式

For each test case, output one line containing "Case #x: y", where xx is the test case number (starting from 1) and yy is the minimum number of clicks to win.

2
3
..*
..*
**.
5
..*..
..*..
.*..*
.*...
.*...
Case #1: 2
Case #2: 8

提示

Limits

1T1001 \le T \le 100.

Small dataset (Test Set 1 - Visible)

1N501 \le N \le 50.

Large dataset (Test Set 2 - Hidden)

1N3001 \le N \le 300.