你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统。游戏的目标是找到所有地雷在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. SQL Server 2012 手动安装帮助文档+排错

    逆天SQL Server 2012装的不要不要的,最后发现...竟然没帮助文档...汗啊!原来它跟vs一样要自己装帮助文档...好吧,官网一下载,妹的...报错...然后就让我们还原这个安装过程以及逆 ...

  2. c函数指针

    #include <stdio.h> int max(int a, int b){ return a > b ? a : b; } int min(int a, int b){ re ...

  3. 什么是JDK?什么是JRE?JDK与JRE的区别和用途

    一.编程环境与运行环境 JDK(Java Development Kit)称为Java开发包或Java开发工具.是一个编写Java的Applet小程序和应用程序的程序开发环境.JDK是整个Java的核 ...

  4. AppiumLibrary常用关键字

    通过上一章节,open application关键字的使用,相信大家对手机自动化充满了兴趣,那么今天这一章节,主要介绍AppiumLibrary中常用关键字的使用. 一.实用函数 关键字 含义 实例 ...

  5. LeetCode算法题-Missing Number(Java实现-四种解法)

    这是悦乐书的第200次更新,第209篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第65题(顺位题号是268).给定一个包含n个不同数字的数组,取自0,1,2,...,n ...

  6. 我为什么要写 blog?

    从事软件测试工作10余年,也没在网上留下些什么.最近忙着找工作,年龄上又遇到了瓶颈,发现好多工作岗位需要技术博客,正好趁这个机会,梳理一下自己的知识点,记录下来和大家一起学习探讨,共同进步.欢迎加我微 ...

  7. nginx 拦截 swagger 登录

    随着微服务的也来越多,每个服务都有单独的文档,那么问题来了,怎么把所有文档整合在一起呢 本方法采用服务器拦截的方式进行处理 首先需要在opt 的主目录中 /opt/ 创建一个新文件 htpasswd此 ...

  8. 在模态框(Modal)中使用UEditor全屏显示的一个坑

    根据这个问题很简单就能查到一些文章明确说明了解决问题的方法,就是如下一段代码: var isModal = false; //判断该dom是否为modal var classes = $(contai ...

  9. Python取整函数

    ceil() 向上取整 返回数字的上入整数,如ceil(4.1) 返回 5 ceil()接受的参数必须是数字类型,可以是True或者False,True(代表1),False(代表0),我试了ceil ...

  10. Maven中POM.XML详解

    转自https://blog.csdn.net/jariwsz/article/details/19554137 我们先看一个简单的例子: <project xmlns="http:/ ...