Mineweep(扫雷)
题目描述:
每周一题之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(扫雷)的更多相关文章
- jquery在线扫雷
<扫雷>是一款大众类的益智小游戏,于1992年发行.游戏目标是在最短的时间内根据点击格子出现的数字找出所有非雷格子,同时避免踩雷. 在线试玩 http://hovertree.com/te ...
- wpf版扫雷游戏
近来觉得wpf做出来的界面很拉风,自己也很喜欢搞些小游戏,感觉这做出来的会很炫,很装逼,(满足自己的一点小小的虚荣心)于是就去自学,发现感觉很不错,可是属性N多,太多了,而且质料也少,很多不会用,只会 ...
- Java课程设计——扫雷(winmine)
因为是我的课程设计,要是有冲突就不好了,转载注明出处!!! 程序很简单,毕竟我是搞acm的,我就只介绍一下闪光点. 中心空白搜索的时候,我用的DFS: 有一点是要注意的,就是JFrame不支持重画,还 ...
- Java GUI编程-(项目代码_扫雷_弹钢琴)
--扫雷 package com;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionLis ...
- js版扫雷(可直接运行试玩)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- BZOJ1088扫雷Mine 解析报告
1088: [SCOI2005]扫雷Mine Description 相信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”人国流行起了一种简单的扫 ...
- C+命令行+方向键=简易版扫雷
前言: 想起来做这个是因为那时候某天知道了原来黑框框里面的光标是可以控制的,而且又经常听人说起这个,就锻炼一下好了. 之前就完成了那1.0的版本,现在想放上来分享却发现有蛮多问题的,而且最重要的是没什 ...
- BZOJ 1088 扫雷Mine
今天做了几道BZOJ的题,发现统观题目时还是很多很多都不会的,不过还是有几道时可以作的,以后要慢慢加强,争取多做题 BZOJ 1088 扫雷 其实本人平常不大玩扫雷的,就算玩也不是很好,不过看n*2的 ...
- hiho #1114 : 小Hi小Ho的惊天大作战:扫雷·一
#1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...
随机推荐
- Eclipse一步一步搭建SSM+Maven
Eclipse 搭建SSM(Spring.Spring MVC .Mybatis) 利用Maven管理Jar包 一般而言,新的eclipse都已经集成了maven,如果没有那么 ...
- 【Android 多媒体应用】使用MediaCodec解码使用SurfaceView显示视频
1.MainActivity.java import android.app.Activity; import android.os.Bundle; import android.os.Environ ...
- ffmpeg一揽子
avformat_alloc_output_context2().在基于FFmpeg的视音频编码器程序中,该函数通常是第一个调用的函数(除了组件注册函数av_register_all()).avfor ...
- DAY17-Django之model增删改
添加表记录 普通字段 #方式1 publish_obj=Publish(name="人民出版社",city="北京",email="renMin@16 ...
- adb device offline 解决办法
当电脑中的豌豆荚之类的应用打开的状态下 adb devices 显示连接状态 关闭手机助手之后,adb devices总显示 device offline 后来发现sdk platform-tool ...
- Mac系统下MySql下载MySQL5.7及详细安装流程
一.在浏览器当中输入以下地址 https://dev.mysql.com/downloads/mysql/ 二.进入以下界面:直接点击下面位置 ,选择跳过登录 点过这后直接下载. 三.下载完成后 ...
- 解决iText+freemark导出pdf不支持base64的解决办法
工具类: package test; import java.io.IOException ; import org.w3c.dom.Element ; import org.xhtmlrendere ...
- windows 7 系统装机优化
A:系统设置 1.控制面板\系统和安全\Windows Update\更改设置 把系统升级以及提示关闭 控制面板\系统和安全\Windows 防火墙\自定义设置 把专用网络和公共网络的防火 ...
- JavaWeb 没用
Servlet的生命周期 初始化:Web容器加载servlet,调用innit(),只执行一次 处理业务: 请求到达时,运行service方法 并调用相应的doget或者dopost方法. 可执行多 ...
- [转载]/etc/security/limits.conf解释及应用
limits.conf的格式如下: username|@groupname type resource limit username|@groupname:设置需要被限制的用户名,组名前面加@和用户名 ...