题目描述:

每周一题之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. 部署和调优 1.7 samba 部署和优化-1

    Samba服务可以实现linux上共享一个目录,windows上面访问. 安装 yum install -y samba samba-client 配置文件在 vim /etc/samba/smb.c ...

  2. 【转】Sublime Text2中的快捷键一览表(Sublime 键盘快捷键大全 )

    Sublime Text 提供了无比强大的快捷键阵容,如果能够在Coding的时候灵活的使用快捷键,将能够使得你的效率倍增,相信在不久的将来,Sublime Text将是你跨平台使用的最佳Coding ...

  3. 环境变量,include搜索路径,lib库搜索路径

    环境变量 系统环境变量 我们知道,我们经常要设置一些环境变量,系统环境变量我们非常容易理解.其实我们在windows中经常容易接触.其实环境变量是一个非常广泛的一个概念,它与web应用程序中的web. ...

  4. Windows系统上release版本程序bug跟踪解决方案-.dmp文件。

    使用场景: Win32程序在release模式下编译完成,发送给最终用户使用时,我们的程序有时候也会出现崩溃的情况,这个时候如果能快速定位崩溃原因或提供一些程序崩溃时的状态信息,对我们解决问题将会带来 ...

  5. [P4782]2-SAT问题

    解题关键:2-sat模板,tarjan解决. #include<iostream> #include<cstring> #include<cstdio> #incl ...

  6. go语言的第一个helloworld

    1.新建一个hello.go文件 添加如下代码: package main  // 代码包声明语句. import "fmt" //系统包用来输出的 func main() { / ...

  7. ReactNative http网络通讯

    安装 fetch npm install whatwg-fetch --save 1.fetch的Get方式通讯 async sendGet(){ let response = await fetch ...

  8. Condition实现多个生产者多个消费者

    Condition实现多对多交替打印: import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.R ...

  9. IDEA java 代码格式化统一

    Intellij idea 安装格式化插件 ECLIPSE CODE FORMATTER:1,安装插件:网络安装:选择Setting =>Plugins=>Browse repositor ...

  10. Arduino 002 --- 在Ubuntu(Linux) 中搭建Arduino开发环境

    在Ubuntu/Linux 中搭建Arduino开发环境 我的Ubuntu系统:Ubuntu 14.04.10 TLS 32位 需要安装的Arduino的版本:Arduino 1.6.11(最新版本) ...