#P13245. [GCJ 2014 Qualification] Minesweeper Master

    ID: 15111 远端评测题 3000~5000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>搜索2014Special Judge枚举深度优先搜索 DFSGoogle Code Jam

[GCJ 2014 Qualification] Minesweeper Master

题目描述

Minesweeper is a computer game that became popular in the 1980s, 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 0, and its 8 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. There is nothing quicker than winning in one click. Given the size of the board (R×CR \times C) and the number of hidden mines MM, is it possible (however unlikely) to win in one click? You may choose where you click. If it is possible, then print any valid mine configuration and the coordinates of your click, following the specifications in the Output section. Otherwise, print "Impossible".

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow. Each line contains three space-separated integers: RR, CC, and MM.

输出格式

For each test case, output a line containing "Case #xx:", where xx is the test case number (starting from 11). On the following RR lines, output the board configuration with CC characters per line, using '.' to represent an empty cell, '*' to represent a cell that contains a mine, and 'c' to represent the clicked cell.

If there is no possible configuration, then instead of the grid, output a line with "Impossible" instead. If there are multiple possible configurations, output any one of them.

5
5 5 23
3 1 1
2 2 1
4 7 3
10 10 82
Case #1:
Impossible
Case #2:
c
.
*
Case #3:
Impossible
Case #4:
......*
.c....*
.......
..*....
Case #5:
**********
**********
**********
****....**
***.....**
***.c...**
***....***
**********
**********
**********

提示

Limits

0M<R×C0 \leq M < R \times C.

Small dataset(11 Pts)

  • Time limit: 60 3 seconds.
  • 1T2301 \leq T \leq 230.
  • 1R,C51 \leq R, C \leq 5.

Large dataset(24 Pts)

  • Time limit: 120 5 seconds.
  • 1T1401 \leq T \leq 140.
  • 1R,C501 \leq R, C \leq 50.