Problem Description
I think most of you are using system named of xp or vista or win7.And these system is consist of a famous game what is mine sweeping.You must have played it before.If you not,just look the game rules followed.
There are N*N grids on the map which contains some mines , and if you touch that ,you lose the game.If a position not containing a mine is touched, an integer K (0 < =K <= 8) appears indicating that there are K mines in the eight adjacent positions. If K = 0, the eight adjacent positions will be touched automatically, new numbers will appear and this process is repeated until no new number is 0. Your task is to mark the mines' positions without touching them.
Now, given the distribution of the mines, output the numbers appearing after the player's first touch.
Input
The first line of each case is two numbers N (1 <= N <= 100) .Then there will be a map contain N*N grids.The map is just contain O and X.'X' stands for a mine, 'O' stand for it is safe with nothing. You can assume there is at most one mine in one position. The last line of each case is two numbers X and Y(0<=X<N,0<=Y<N, indicating the position of the player's first touch.
Output
If the player touches the mine, just output "it is a beiju!".
If the player doesn't touch the mine, output the numbers appearing after the touch. If a position is touched by the player or by the computer automatically, output the number. If a position is not touched, output a dot '.'.
Output a blank line after each test case.
Sample Input
5
OOOOO
OXXXO
OOOOO
OXXXO
OOOOO
1 1
5
OOOOO
OXXXO
OOOOO
OXXXO
OOOOO
0 0
Sample Output
it is a beiju!
1....
.....
.....
.....
.....
扫雷游戏,简单题
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(i,j,k) for (int i = j; i <= k; i++)
const int N = 1e2 + 10;
char s[N];
int mp[N][N], f[N][N], g[N][N];
int n, x, y;
int a[8] = { -1,-1,-1,0,0,1,1,1 };
int b[8] = { -1,0,1,-1,1,-1,0,1 };
void dfs(int x, int y)
{
if (g[x][y] != -1 || f[x][y]) {
g[x][y] = f[x][y]; return;
}
g[x][y] = f[x][y];
rep(i, 0, 7) dfs(x + a[i], y + b[i]);
}
int main()
{
while (scanf("%d", &n) != EOF)
{
rep(i, 1, n)
{
scanf("%s", s + 1);
rep(j, 1, n) mp[i][j] = s[j] == 'X';
}
rep(i, 1, n) rep(j, 1, n)
{
g[i][j] = -1; f[i][j] = 0;
rep(k, 0, 7)
{
f[i][j] += mp[i + a[k]][j + b[k]];
}
}
scanf("%d%d", &x, &y);
x++; y++;
if (mp[x][y]) { printf("it is a beiju!\n\n"); continue; }
if (f[x][y]) g[x][y] = f[x][y];
else dfs(x, y);
rep(i, 1, n)
{
rep(j, 1, n)
{
printf("%c", g[i][j] == -1 ? '.' : '0' + g[i][j]);
}
putchar(10);
}
putchar(10);
}
return 0;
}