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.
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.
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.
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
M2..111..
M3111M1..
12M1111..
.111...11
.111..13M
.1M1112MM
12211M222
1M1.111..
111......
.....
.111.
.1M1.
.111.
.....
水题:不BB了,这都写半天,格式还出错~~菜啊~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<stdio.h>
#include<map>
#include<vector>
#define min(a,b)(a<b?a:b)
#define max(a,b)(a>b?a:b)
#define INF 0x3f3f3f3f
typedef
long
long
ll;
using
namespace
std;
#define N 110000
char
maps[11][11];
int
n,m;
int
dir[8][2]={1,1,1,0,1,-1,0,1,0,-1,-1,-1,-1,0,-1,1};
void
Find(
int
x,
int
y)
{
int
sum=0;
for
(
int
i=0;i<8;i++)
{
int
dx=x+dir[i][0];
int
dy=y+dir[i][1];
if
(dx>0 && dy>0 && dx<=n && dy<=m && maps[dx][dy]==
'M'
)
sum++;
}
if
(sum==0)
printf
(
"."
);
else
printf
(
"%d"
,sum);
}
int
main()
{
int
T,i,j,k,x,y,f=0;
scanf
(
"%d"
,&T);
while
(T--)
{
if
(f!=0)
printf
(
"\n"
);
f++;
memset
(maps,0,
sizeof
(maps));
scanf
(
"%d%d%d"
,&n,&m,&k);
for
(i=0;i<k;i++)
{
scanf
(
"%d%d"
,&x,&y);
maps[x][y]=
'M'
;
}
for
(i=1;i<=n;i++)
{
for
(j=1;j<=m;j++)
{
if
(maps[i][j]==
'M'
)
printf
(
"M"
);
else
{
Find(i,j);
}
}
printf
(
"\n"
);
}
}
return
0;
}
/**************************************************************
Problem: 3
User: team912
Language: C++
Result: Accepted
Time:0 ms
Memory:1504 kb
****************************************************************/
|