首页 > 其他分享 >HDU 3316 Mine sweeping

HDU 3316 Mine sweeping

时间:2022-11-09 20:34:21浏览次数:46  
标签:HDU int rep Mine mine touch mp sweeping output


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;
}



标签:HDU,int,rep,Mine,mine,touch,mp,sweeping,output
From: https://blog.51cto.com/u_15870896/5838733

相关文章

  • HDU 3355 Hop — Don’t Walk!
    ProblemDescriptionKERMITTHEFROGisaclassicvideogamewithasimplecontrolandobjectivebutrequiresagooddealofthinking.Youcontrolanani......
  • HDU 3427 Clickomania
    ProblemDescriptionClickomaniaisapuzzleinwhichonestartswitharectangulargridofcellsofdifferentcolours.Ineachstep,aplayerselects("......
  • HDU 2209 翻纸牌游戏
    ProblemDescription有一种纸牌游戏,很有意思,给你N张纸牌,一字排开,纸牌有正反两面,开始的纸牌可能是一种乱的状态(有些朝正,有些朝反),现在你需要整理这些纸牌。但是麻烦的是,......
  • HDU 2216 Game III
    ProblemDescriptionZjtandSarawilltakepartinagame,namedGameIII.ZjtandSarawillbeinamaze,andZjtmustfindSara.Therearesomestrang......
  • HDU 1010 Tempter of the Bone
    DescriptionThedoggiefoundaboneinanancientmaze,whichfascinatedhimalot.However,whenhepickeditup,themazebegantoshake,andthedoggie......
  • HDU 1017 A Mathematical Curiosity
    DescriptionGiventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0<a<b<nand(a^2+b^2+m)/(ab)isaninteger. Thi......
  • HDU 5605 geometry
    ProblemDescriptionThereisapoint  atcoordinate .Alinegoesthroughthepoint,andintersectswiththepostivepartof  axesatpoint .Plea......
  • HDU 1329 Hanoi Tower Troubles Again!
    DescriptionPeoplestoppedmovingdiscsfrompegtopegaftertheyknowthenumberofstepsneededtocompletetheentiretask.Butontheotherhand,they......
  • HDU 2475 Box
    DescriptionThereareNboxesontheground,whicharelabeledbynumbersfrom1toN.Theboxesaremagical,thesizeofeachonecanbeenlargedorreduc......
  • HDU 5432 Pyramid Split
    ProblemDescriptionXiaoMingisacitizenwho'sgoodatplaying,hehaslot'sofgoldconeswhichhavesquareundersides,let'scallthempyramids.Anyo......