你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统。游戏的目标是找到所有地雷在M x N场中的位置。游戏在一个正方形中显示一个数字,它告诉你在这个正方形附近有
多少个地雷。每个方块最多有八个相邻方块。左侧的4x 4字段包含两个地雷,每个地雷由一个“`*”字符表示。如果我们用上面描述的提示数来表示同一个字段,
我们最后得到右边的字段:*……*…*100 2210 1*10 1110
输入将由任意数量的字段组成。每个字段的第一行包含两个整数n和m(0<n,m$\le$100),分别代表字段的行数和列数。接下来的n行中的每一行正好包含m个字符,表示字段。安全方格
用`.'表示,矿山方格用`.*表示,两者都没有引号。n=m=0的第一行字段表示输入结束,不应进行处理。
For each field, print the message Field #x: on a line alone, where x stands for the number of the field starting from 1. The next n lines
should contain the field withthe ``.'' characters replaced by the number of mines adjacent to that square. There must be an empty line
between field outputs.
对于每个字段,单独在一行上打印消息字段x,其中x代表从1开始的字段编号。接下来的n行应该包含带有“..”字符的字段,替换为该广场附近的地雷数量。字段输出之间必须有空行。
//扫雷游戏
#include<iostream>
#include<cstring>
using namespace std;
int i,j;
char g[][];
int book[][];
int gcd(int x,int y){
int num=;
if(g[x][y]=='*') return -;
// cout<<"hello"<<endl;
for(int xx=x-;xx<=x+;xx++){
for(int yy=y-;yy<=y+;yy++){ if(xx==x&&yy==y) continue;
if(g[xx][yy]=='*') num++;
}
}
return num;
}
int main()
{
memset(book,,sizeof(book));
memset(g,,sizeof(g)); int m,n;
int num=;
while(cin>>m>>n&&m&&n){
num++;
memset(book,,sizeof(book));
memset(g,,sizeof(g));
for(i=;i<=m;i++){
for(j=;j<=n;j++)
cin>>g[i][j];
}
for(i=;i<=m;i++){
for(j=;j<=n;j++){
book[i][j]=gcd(i,j);
} }
printf("Field #%d:\n",num);
for(i=;i<=m;i++){
for(j=;j<=n;j++){
if(book[i][j]!=-) cout<<book[i][j];
else cout<<"*";
// cout<<book[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
}

广度优先搜索就行

主要问题是害怕看英文,多看看英语阅读

题目描述
Minesweeper Have you ever played Minesweeper? This cute little game comes with a certain
operating system whose name we can't remember. The goal of the game is to find where all
the mines are located within a M x N field. The game shows a number in a square which tells
you how many mines there are adjacent to that square. Each square has at most eight
adjacent squares. The 4 x 4 field on the left contains two mines, each represented by a ``*''
character. If we represent the same field by the hint numbers described above, we end up with
the field on the right: *... .... .*.. .... *100 2210 1*10 1110
输入
The input will consist of an arbitrary number of fields. The first line of each field contains two
integers n and m ( 0 < n, m$ \le$100) which stand for the number of lines and columns of the
field, respectively. Each of the next n lines contains exactly m characters, representing the field. Safe squares are denoted by ``.'' and mine squares by ``*,'' both without the quotes. The first field line where n = m = 0 represents the end of input and should not be processed.
输出
For each field, print the message Field #x: on a line alone, where x stands for the number of the field starting from 1. The next n lines should contain the field with the ``.'' characters replaced by the number of mines adjacent to that square. There must be an empty line between field outputs.
样例输入
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0
样例输出
Field #1:
*100
2210
1*10
1110 Field #2:
**100
33200
1*100

  

 

Minesweeper的更多相关文章

  1. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)

    Problem B: Minesweeper Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 29  Solved: 7[Submit][Status][W ...

  2. [LeetCode] Minesweeper 扫雷游戏

    Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...

  3. [Swift]LeetCode529. 扫雷游戏 | Minesweeper

    Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...

  4. 529. Minesweeper扫雷游戏

    [抄题]: Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repre ...

  5. LeetCode 529. Minesweeper

    原题链接在这里:https://leetcode.com/problems/minesweeper/description/ 题目: Let's play the minesweeper game ( ...

  6. leetcode笔记(七)529. Minesweeper

    题目描述 Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repres ...

  7. Google Code Jam 2014 资格赛:Problem C. Minesweeper Master

    Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...

  8. 529 Minesweeper 扫雷游戏

    详见:https://leetcode.com/problems/minesweeper/description/ C++: class Solution { public: vector<ve ...

  9. YTU 1099: Minesweeper

    1099: Minesweeper 时间限制: 1 Sec  内存限制: 64 MB 提交: 180  解决: 98 题目描述 Minesweeper Have you ever played Min ...

随机推荐

  1. Springboot helloworld入门最经典例子

    一.建立maven java项目 导入springboot包 二.配置pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0 ...

  2. [20181130]如何猜测那些值存在hash冲突.txt

    [20181130]如何猜测那些值存在hash冲突.txt --//今年6月份开始kerrycode的1个帖子提到子查询结果缓存在哈希表中情况:--//链接:http://www.cnblogs.co ...

  3. [20180828]exadata--豆腐渣系统的保护神.txt

    [20180828]exadata--豆腐渣系统的保护神.txt --//昨天看awr报表发现如下,时间8-9点报表,这个时间病房业务很少,主要门诊的业务: 1.awr报表情况:Top 10 Fore ...

  4. Powershell远程执行命令

    $Username = 'xx' $Password = 'xx' $ComputerName='xx' $pass = ConvertTo-SecureString -AsPlainText $Pa ...

  5. php快速定位当前调用的类的位置

    php快速定位当前调用的类的位置 $func = new ReflectionMethod('类名', '方法名'); $start = $func->getStartLine() - 1; $ ...

  6. Nginx使用教程(三):Nginx配置性能优化之I/O和TCP配置

    配置Nginx I/O <br\> Sendfile 当应用程序传输文件时,内核首先缓冲数据,然后将数据发送到应用程序缓冲区. 应用程序反过来将数据发送到目的地. Sendfile方法是一 ...

  7. ubuntu 安装 GCC 和 G++ C++ 开发环境

    1.先安装 :sudo apt-get install build-essential 2.查看 gcc 版本 然后安装 统一版本的 g++ gcc --version gcc (Ubuntu/Lin ...

  8. MyBatis知识点总结(一)

    前言:本篇主要记录在MyBatis学习过程中的主要知识点. 1.mybatis环境的搭建,通过maven可以快速的进行环境的搭建. <!--文件版本--> <properties&g ...

  9. python nt, bool, str 试题

    # 1.有变量量name = "aleX leNb" 完成如下操作:name = "aleX leNb"# 1)移除 name 变量对应的值两边的空格,并输出处 ...

  10. C#进阶のMEF注入

    1.什么是MEF 先来看msdn上面的解释:MEF(Managed Extensibility Framework)是一个用于创建可扩展的轻型应用程序的库. 应用程序开发人员可利用该库发现并使用扩展, ...