您的位置:首页 > 其它

Problem C: Mine Sweeping Game (华中农业预赛)

2016-05-14 16:38 281 查看

Problem C: Mine Sweeping Game

Time Limit: 1 Sec Memory Limit: 128 MB

Submit: 237 Solved: 127

[Submit][Status][Web
Board]

Description

As everyone knows, Mine Sweeping is a very famous computer game. When Diao Fei was young, he also liked to play this game very much. A sample of situation when win the game is like this below:



In a situation of winning this game, there are three kinds of grid:

·number grid:the grid has a number in it.Like


·blank grid:the grid has nothing in it. Like


·mine grid:the grid has a mine in it. Like


The game’s rule is that, if a grid is a number grid and it has an number x in it, the eight grids (up, down, left, right, up-left, up-right, down-left, down-right, if exists) which around it should have excatly
x mine grids in total. If a grid is a blank grid, then any grid around it should not be a mine grid.

Now the problem is, in a situation of winning this game, giving all of the mine grids, your task is to determine what kind the remain grids are.

Input

The first line contains an integer T, indicating the total number of test cases.

In each test case, the first line is three integers N, M,
K(


,

) indicating the game size is
N rows (numbered from 1 to N) and M columns (numbered from
1 to M), and there are K mines in total. Then K lines follow, each line contains two integersx,
y(

,


) indicating the grid in xth row and
yth column is a mine grid. You can assume that there are not any two mine grids in the same position.

Output

For each test case, output N lines, each line contain M characters, the jth character in the
ith line indicates the grid in the ith row and the jth column. If the grid is a number grid, output the number in the grid. If the grid is a blank grid, output the character ‘.’ (without quotes). If the grid is a mine grid, output
the character ‘M’ (without quotes). Notice that after each test case, you should output a blank line at the end.

Sample Input

2
9 9 10
1 1
2 1
2 6
3 3
5 9
6 3
6 8
6 9
7 6
8 2
5 5 1
3 3

Sample Output

M2..111..
M3111M1..
12M1111..
.111...11
.111..13M
.1M1112MM
12211M222
1M1.111..
111......

.....
.111.
.1M1.
.111.
.....

HINT

水题:不BB了,这都写半天,格式还出错~~菜啊~

?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: