Minesweeper
你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统。游戏的目标是找到所有地雷在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的更多相关文章
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)
Problem B: Minesweeper Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 29 Solved: 7[Submit][Status][W ...
- [LeetCode] Minesweeper 扫雷游戏
Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...
- [Swift]LeetCode529. 扫雷游戏 | Minesweeper
Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...
- 529. Minesweeper扫雷游戏
[抄题]: Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repre ...
- LeetCode 529. Minesweeper
原题链接在这里:https://leetcode.com/problems/minesweeper/description/ 题目: Let's play the minesweeper game ( ...
- leetcode笔记(七)529. Minesweeper
题目描述 Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repres ...
- 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 ...
- 529 Minesweeper 扫雷游戏
详见:https://leetcode.com/problems/minesweeper/description/ C++: class Solution { public: vector<ve ...
- YTU 1099: Minesweeper
1099: Minesweeper 时间限制: 1 Sec 内存限制: 64 MB 提交: 180 解决: 98 题目描述 Minesweeper Have you ever played Min ...
随机推荐
- mysql练习----Self join
stops(id, name) route(num,company,pos, stop) stops route id num name company pos stop
- 打印窗口时,一张A4纸单位为缇的大小
一张A4长297毫米也就是16839.9twip宽210毫米就是11907twip
- [Hive_5] Hive 的 JDBC 编程
0. 说明 Hive 的 JDBC 编程 1. hiveserver2 介绍 hiveserver2 是 Hive 的 JDBC 接口,用户可以连接此端口来连接 Hive 服务器 JDBC 驱动类为 ...
- Python: 遍历
======================遍历列表========================# 直接遍历list: for elem in list: pass # 通过索引获取 for i ...
- Java入门(六):数组
数组是一种数据结构,用于存储同一类型值的集合,也可以看做是数据类型一致的一组数据. 一.语法和声明数组 1.语法:数据类型[ ] array = new 数据类型[长度]: 注意: 使用长度创建数组的 ...
- elixir mix 简介
概述 mix 是 elixir 工程的构建工具,利用 mix,可以快速方便的创建 elixir 工程,写单元测试,管理 elixir 包的依赖管理等等. 我觉得刚开始学习 elixir 的时候,先简单 ...
- MySQL高级知识(十五)——主从复制
前言:本章主要讲解MySQL主从复制的操作步骤.由于环境限制,主机使用Windows环境,从机使用用Linux环境.另外MySQL的版本最好一致,笔者采用的MySQL5.7.22版本,具体安装过程请查 ...
- 设计模式のPrototypePattern(原型模式)----创建模式
一.产生的背景 这种模式是实现了一个原型接口,该接口用于创建当前对象的克隆.当直接创建对象的代价比较大时,则采用这种模式.例如,一个对象需要在一个高代价的数据库操作之后被创建.我们可以缓存该对象,在下 ...
- WPF中应用字体图标
一.什么是字体图标 我们在进行GDI(图形界面)编程的过程中图标是不可少的.近些年随着网络的繁荣和移动应用的繁荣,矢量图的应用越来越火. 矢量图是一种用数学方法描述的.由一系列点和线组成的图,因此相比 ...
- Your kernel does not support swap limit capabilities.memory limit without swap
原因是:由于内核不支持限制内存的设置 解决办法是:vim /etc/default/grub 修改为: 或者:GRUB_CMDLINE_LINUX="cgroup_enable=memory ...