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 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...
随机推荐
- 问题:asp.net 点击button按钮调到页面顶部;结果:asp.net点击一个按钮,使页面跳转到本面页上的指定位置
asp.net点击一个按钮,使页面跳转到本面页上的指定位置 (2011-04-19 16:46:51) 转载▼ 标签: it 最近在做一个项目. 用到标题所说的功能. 实现方法: 1.在aspx中 ...
- linux命令-分区表fstab
磁盘分区后需要格式化,挂载之后才能使用 我们有开机后自动挂载的需求,方法有两种 1.配置文件的形式,把mount写到配置文件里去 cat /etc/fstab 2.把挂载命令写到一个文件里 ls /e ...
- struts2学习笔记(1)配置与基本操作
主要作用:将请求与页面区分开 配 置: 下载struts 2.0,在安装路径D:\项目学习\三大框架视屏\struts-2.3.24-all\struts-2.3.24\apps 中解压struts2 ...
- to_date() 、to_char()、to_number的FMT格式
元素 含义 结果:2018/01/12(周五) - / , . ; : (6中不同分隔符) 分隔符 y 显示一位年份 8 yy 显示二位年 ...
- CDN原理解析
首先,让我们来看一下传统的Internet网络的基本结构和数据传输情况,如下图所示 根据传统的网络结构,用户的访问流程基本如下: 用户在自己的浏览器中输入要访问的网站的域名 浏览器向本地DNS请求 ...
- [poj1509]Glass Beads(最小表示法)
题目大意:求循环同构的字符串的最小字典序. 解题关键:最小表示法模板题. #include<cstdio> #include<cstring> #include<algo ...
- little case1
这句话有问题: frame.setContentPane().add(button); The method setContentPane(Container) in the type JFrame ...
- 在windows远程提交任务给Hadoop集群(Hadoop 2.6)
我使用3台Centos虚拟机搭建了一个Hadoop2.6的集群.希望在windows7上面使用IDEA开发mapreduce程序,然后提交的远程的Hadoop集群上执行.经过不懈的google终于搞定 ...
- SpringMVC 配置式开发-BeanNameUrlHandlerMapping(七)
第一种处理器映射器BeanNameUrlHandlerMapping.class(注册器映射器 bean节点的class属性中用到的,这种方式dean id属性必须要以“/”开头) 第二种处理器映射 ...
- GridView里的按钮事件
http://www.cnblogs.com/insus/archive/2012/09/22/2697862.html using System;using System.Collections.G ...