题目描述:

每周一题之2  Mineweep(扫雷)

Minesweeper (扫雷)

PC/UVa IDs: 110102/10189,

Popularity: A,

Success rate: high Level: 1

测试地址:https://vjudge.net/problem/UVA-10189

[问题描述]

Have you ever played Minesweeper? It’s a cute little game which comes within a certain Operating

System which name we can’t really remember. Well, the goal of the game is to find where are all the mines within a M × N field. To help you, the game shows a number in a square which tells you how many mines there are adjacent to that square. For instance, supose the following 4 × 4 field with 2 mines (which are represented by an ‘*’ character):

*...

....

.*..

....

If we would represent the same field placing the hint numbers described above, we would end up

with:

*100

2210

1*10

1110

As you may have already noticed, each square may have at most 8 adjacent squares.

[输入]

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 ≤ 100) which stands for the number of lines and columns of the field respectively.

The next n lines contains exactly m characters and represent the field.

Each safe square is represented by an ‘.’ character (without the quotes) and each mine square

is represented by an ‘*’ character (also without the quotes). The first field line where n = m = 0

represents the end of input and should not be processed.

下面这段话蓝桥官方误导:

[输出]

对于每对整数 i 和 j,按原来的顺序输出 i 和 j,然后输出二者之间的整数中的最大循环节长度。这三个整数应该用单个空格隔开,且在同一行输出。对于读入的每一组数据,在输出中应位于单独的一行。

[样例输入]

4 4

*...

....

.*..

....

3 5

**...

.....

.*...

0 0

[样例输出]

Field #1:

*100

2210

1*10

1110

Field #2:

**100

33200

1*100

*/

解析:

1.处理好边界:

2. 遍历每个点的每个方向,操作结课

AC代码:

package december.year18;

import java.util.Scanner;

public class Solution2 {

    static int [] x={0,0,1,-1,1,-1,-1,1};
static int [] y={1,-1,0,0,1,-1,1,-1}; public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cindex=1;
while (in.hasNext()) {
int n = in.nextInt();
int m = in.nextInt();
if(m==0&&m==n) {
return;
}
char[][] mat = new char[n][]; for (int i = 0; i < mat.length; i++) {
mat[i]=in.next().toCharArray();
} int mL=mat[0].length;
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mL; j++) {
if(mat[i][j]!='*') {
for (int k = 0; k < 8; k++) {
int newx=i+x[k];
int newy=j+y[k];
if(newx>=0&&newy>=0&&newx<n&&newy<mL) {
if(mat[newx][newy]=='*') {
if(mat[i][j]=='.') {
mat[i][j]='0';
}
mat[i][j]++;
}
}
}
}
}
}
if(cindex>1)System.out.println();
System.out.println("Field #"+cindex+":");
cindex++;
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat[i].length; j++) {
if(mat[i][j]=='.') {
System.out.print('0');
}else {
System.out.print(mat[i][j]);
}
}
System.out.println();
}
}
} }

Mineweep(扫雷)的更多相关文章

  1. jquery在线扫雷

    <扫雷>是一款大众类的益智小游戏,于1992年发行.游戏目标是在最短的时间内根据点击格子出现的数字找出所有非雷格子,同时避免踩雷. 在线试玩 http://hovertree.com/te ...

  2. wpf版扫雷游戏

    近来觉得wpf做出来的界面很拉风,自己也很喜欢搞些小游戏,感觉这做出来的会很炫,很装逼,(满足自己的一点小小的虚荣心)于是就去自学,发现感觉很不错,可是属性N多,太多了,而且质料也少,很多不会用,只会 ...

  3. Java课程设计——扫雷(winmine)

    因为是我的课程设计,要是有冲突就不好了,转载注明出处!!! 程序很简单,毕竟我是搞acm的,我就只介绍一下闪光点. 中心空白搜索的时候,我用的DFS: 有一点是要注意的,就是JFrame不支持重画,还 ...

  4. Java GUI编程-(项目代码_扫雷_弹钢琴)

    --扫雷 package com;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionLis ...

  5. js版扫雷(可直接运行试玩)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. BZOJ1088扫雷Mine 解析报告

    1088: [SCOI2005]扫雷Mine Description 相信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”人国流行起了一种简单的扫 ...

  7. C+命令行+方向键=简易版扫雷

    前言: 想起来做这个是因为那时候某天知道了原来黑框框里面的光标是可以控制的,而且又经常听人说起这个,就锻炼一下好了. 之前就完成了那1.0的版本,现在想放上来分享却发现有蛮多问题的,而且最重要的是没什 ...

  8. BZOJ 1088 扫雷Mine

    今天做了几道BZOJ的题,发现统观题目时还是很多很多都不会的,不过还是有几道时可以作的,以后要慢慢加强,争取多做题 BZOJ 1088 扫雷 其实本人平常不大玩扫雷的,就算玩也不是很好,不过看n*2的 ...

  9. hiho #1114 : 小Hi小Ho的惊天大作战:扫雷·一

    #1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...

随机推荐

  1. docker 笔记 (5)常用命令

    images    显示镜像列表 history   显示镜像构建历史 commit    从容器创建新镜像 build     从 Dockerfile 构建镜像 tag       给镜像打 ta ...

  2. VS2015 MSVC编译FFMPEG

    1.下载安装msys2 http://www.msys2.org/下载msys2 下载安装完成后,在msys2的shell中安装编译FFMPEG必要的命令行工具 pacman -S make gcc ...

  3. does not contain bitcode. You must rebuild it with

    *** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE ...

  4. DAY10-MYSQL完整性约束

    一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...

  5. springmvc 注解式开发 处理器方法的返回值

    1.返回void -Ajax请求 后台: 前台: 返回object中的数值型: 返回object中的字符串型: 返回object中的自定义类型对象: 返回object中的list: 返回object中 ...

  6. OSI七层网络模型与TCP/IP四层网络模型

    1.OSI网络7层模型 网络协议设计者不应当设计一个单一.巨大的协议来为所有形式的通信规定完整的细节,而应把通信问题划分成多个小问题,然后为每一个小问题设计一个单独的协议.这样做使得每个协议的设计.分 ...

  7. 【android】关于自己实现adapter后gridview中item无法被选中的解决方法

    有时候,自己继承实现了baseadapter将其赋给gridview之后,gridview会十分奇怪的无法选中内部的item. 经过仔细研究,我发现是在继承的时候多复写了几个方法,解决方法就是,只保留 ...

  8. Vbs 脚本编程简明教程之一

    —为什么要使用 Vbs ? 在 Windows 中,学习计算机操作也许很简单,但是很多计算机工作是重复性劳动,例如你每周也许需要对一些计算机文件进行复制.粘贴.改名.删除,也许你每天启动 计算机第一件 ...

  9. debug配置

  10. python-ASCII与Unicode

    # Auther: Aaron Fan'''ASCII:不支持中文,1个英文占1个字节Unicode(万国码,支持所有国家的文字显示):支持中文,但是每个英文和中文都占2个字节UTF-8(是一种针对U ...