#t151. 扫雷
扫雷
Minesweeper
Problem Description
Xiaoyang is playing the classic game "Minesweeper" and wants to generate a Minesweeper map himself.
Xiaoyang wants a map of rows and columns, with cells in total. The rows are numbered and the columns . Some cells are mines; the others are not.
Xiaoyang designates cells as mines, and all other cells are non-mines. He wants you to compute, for each non-mine cell, how many mine cells it is adjacent to.
Two cells are adjacent if and only if they share at least one vertex (that is, for a cell not on the map's edge, the surrounding cells are all adjacent to it).
Input Format
The input contains lines. The first line contains three positive integers , , and : the number of rows, the number of columns, and the number of mines. The following lines each contain two integers: the row and column of the -th mine. The given mines are guaranteed to be distinct.
Output Format
Output lines, each with characters separated by spaces. For cell , output:
*if it is a mine;- otherwise the number of adjacent mines (a digit from
0to8).
Sample Input
3 4 4
1 1
1 3
2 4
3 2
Sample Output
* 2 * 2
2 3 3 *
1 * 2 1
Sample Explanation
From the input, the map is rows and columns with mines at , , , and . In the output * marks a mine; the other digits mark how many mines each non-mine cell is adjacent to. For example, cell (non-mine) is adjacent to three mines , , and , so it outputs ; cell is adjacent to two mines and , so it outputs . The rest follow the same rule, giving the sample output.
Constraints
- The given mines are inside the map and distinct; rows and columns are -indexed.