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 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...
随机推荐
- Android CTS
1.什么是CTS CTS是google制定的兼容性测试包(Compatibility Test Suite),只有通过CTS测试的设备才有可能获得Android的商标和享受Android Market ...
- xcode编写c/c++静态库使用系统头文件问题
c/c++编写的静态库中有引用ios系统头文件比如: #include <EGL/egl.h> 在xcode编译的时候需要设置静态库程序: Build Settings-Header Se ...
- cygwin选择安装包选项搭建NDK开发环境/配置cygwin的root权限
9.Search是可以输入你要下载的包的名称,能够快速筛选出你要下载的包.那四个单选按钮是选择下边树的样式,默认就行,不用动.View默认是Category,建议改成full显示全部包再查,省的一些包 ...
- LaTeX数学公式基础
LaTeX数学公式 参考:https://www.cnblogs.com/Sinte-Beuve/p/6160905.html 原博客显示有点问题,重新搬运整理LaTeX数学公式部分的基本用法 基础 ...
- 属性操作get.Attribute()
- 关于android studio中使用class.forname()方法动态获取类实例报NO CLASS FOUND异常的几种处理方法
最近在做一个项目的时候需要用到反射来回调子类的方法,但是在反射过程中总是在class.forname()方法抛出NO CLASS FOUND异常,经过几部检查,问题解决,在此总结一下引起该问题的原因 ...
- Codeforces #505(div1+div2) B Weakened Common Divisor
题意:给你若干个数对,每个数对中可以选择一个个元素,问是否存在一种选择,使得这些数的GCD大于1? 思路:可以把每个数对的元素乘起来,然后求gcd,这样可以直接把所有元素中可能的GCD求出来,从小到大 ...
- 添加超级链接为什么用a标签
a是anchor的简写,中文意思是锚点,而锚点的引申意思是连接,link已经被html占用了,只能用a来表示连接了.
- [转载]/etc/security/limits.conf解释及应用
limits.conf的格式如下: username|@groupname type resource limit username|@groupname:设置需要被限制的用户名,组名前面加@和用户名 ...
- 2019年第十届蓝桥杯省赛-糖果(一维状压dp)
看到20的数据量很容易想到状压dp. 开1<<20大小的数组来记录状态,枚举n个糖包,将其放入不同状态中(类似01背包思想) 时间复杂度O(n*(2^20)). import java.u ...