Mine Sweeping Game
来源:互联网 发布:淘宝贷款在哪里 编辑:程序博客网 时间:2024/06/06 07:01
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. ThenK lines follow, each line contains two integers x, y(, ) indicating the grid in xth row andyth 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
29 9 101 12 12 63 35 96 36 86 97 68 25 5 13 3
Sample Output
M2..111..M3111M1..12M1111...111...11.111..13M.1M1112MM12211M2221M1.111..111............111..1M1..111......
方法一:
#include<string.h>
#define BANNER 10
int main()
{
int T;
int N,M,K;
int map[11][11];
int key[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
scanf("%d",&T);
while(T--)
{
int x,y;
memset(map,0,sizeof(map));
scanf("%d%d%d",&N,&M,&K);
for(int i=1;i<=K;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=BANNER;
for (int j=0;j<8;j++)
{
map[x+key[j][0]][y+key[j][1]]++;//此处比较重要,当时没想出来。
}
}
for (int i=1;i<=N;i++)
{
for (int j=1;j<=M;j++)
{
if (map[i][j]>=BANNER)
{
printf("M");
}
else if(map[i][j]==0)
{
printf(".");
}
else
{
printf("%d",map[i][j]);
}
}
printf("\n");
}
}
return 0;
}
#include<string.h>
int main()
{
int t,n,m,k,i,j,x[105],y[105];
int map[15][15];
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
memset(map,0,sizeof(map));
for(i=0;i<k;i++)
{
scanf("%d%d",&x[i],&y[i]);
map[x[i]][y[i]]=-1;
}
for(i=0;i<k;i++)
{
if(map[x[i]-1][y[i]-1]!=-1)
map[x[i]-1][y[i]-1]+=1;
if(map[x[i]-1][y[i]]!=-1)
map[x[i]-1][y[i]]+=1;
if(map[x[i]-1][y[i]+1]!=-1)
map[x[i]-1][y[i]+1]+=1;
if(map[x[i]][y[i]-1]!=-1)
map[x[i]][y[i]-1]+=1;
if(map[x[i]][y[i]+1]!=-1)
map[x[i]][y[i]+1]+=1;
if(map[x[i]+1][y[i]-1]!=-1)
map[x[i]+1][y[i]-1]+=1;
if(map[x[i]+1][y[i]]!=-1)
map[x[i]+1][y[i]]+=1;
if(map[x[i]+1][y[i]+1]!=-1)
map[x[i]+1][y[i]+1]+=1;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(map[i][j]==-1)
printf("M");
else if(map[i][j]==0)
{
printf(".");
}
else
{
printf("%d",map[i][j]);
}
}
printf("\n");
}
printf("\n");
}
return 0;
}
- Mine Sweeping Game
- HZAU 1002 Mine Sweeping Game
- NZAU-C-Mine Sweeping Game
- Problem C: Mine Sweeping Game (华中农业预赛)
- HDU 3316 Mine sweeping
- hdu3316 Mine sweeping--DFS
- 南邮 OJ 1149 Mine sweeping
- hdu 3316 Mine sweeping(迷宫)
- hdu 3316 Mine sweeping(BFS)
- HDU 4678 - Mine - BFS + Game Theory
- MINE
- MINE
- mine
- Mine
- fast sweeping method
- Mine Sweeper
- excel mine
- Java mine
- Beautiful numbers
- JVM监控工具介绍
- Android LayoutInflater详解
- Ubuntu日记——codeblock安装及其配置
- 浅谈Map集合
- Mine Sweeping Game
- 【VS开发】【电子电路技术】VPX技术介绍
- 设计一个算法的方法论
- Java千百问_06数据结构(018)_多维数组如何储存在内存中
- 基于SIFT特征的全景图像拼接
- Oracle/Hive/Impala SQL比较(3-4)
- Java使用JNDI技术获取DataSource对象
- asyUI tree点击文字展开节点
- 最长递增子序列算法