UVA10189 Minesweeper【Ad Hoc】
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.
Input
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.
Output
For each field, you must print the following message in a line alone:
Field #x:
Where x stands for the number of the field (starting from 1). The next n lines should contain the field with the ‘.’ characters replaced by the number of adjacent mines to that square. There must be an empty line between field outputs.
Sample Input
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0
Sample Output
Field #1:
*100
2210
1*10
1110
Field #2:
**100
33200
1*100
问题链接:UVA10189 Minesweeper
问题简述:(略)
问题分析:
扫雷游戏是人们熟知的一个计算机游戏,通过这个程序,可以了解其局部的计算是如何实现的。
这是一个简单的计算问题,对于一个位置,直接计算其周围的地雷数量即可。
程序说明:
定义二维数组用于存储扫雷游戏的棋盘时,周围多出一圈,可以省去数组下标的越界判定。
数组around[]存储周围元素的相对下标,使得无序变有序,可以用循环来处理。
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
/* UVA10189 Minesweeper */#include <stdio.h>
#include <string.h>#define AN 8
struct _around {int drow;int dcol;
} around[] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};#define N 100
char a[N+2][N+2];int main(void)
{int n, m, i, j, k, caseno=0;while(~scanf("%d%d", &n, &m) && (n || m)) {memset(a, 0, sizeof(a));for(i=1; i<=n; i++)scanf("%s", a[i]+1);if(caseno)printf("\n");printf("Field #%d:\n", ++caseno);for(i=1; i<=n; i++) {for(j=1; j<=m; j++) {int count = 0;if(a[i][j] != '*') {for(k=0; k<AN; k++)if(a[i + around[k].drow][j + around[k].dcol] == '*')count++;a[i][j] = count + '0';}}}for(i=1; i<=n; i++)printf("%s\n", a[i] + 1);}return 0;
}
UVA10189 Minesweeper【Ad Hoc】相关推荐
- Bailian4137 最小新整数【Ad Hoc】
4137:最小新整数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0.n的位数为m. ...
- Bailian4040 买书问题【Ad Hoc】
4040:买书问题 总时间限制: 1000ms 内存限制: 65536kB 描述 某网上书店举行优惠促销,现有两种优惠策略.策略一是购书总额大于100元的可享受免费送货.策略二是如果购书数量大于3本, ...
- UVA10945 Mother bear【Ad Hoc】
Unforunately for our lazy "heroes", the nuts were planted by an evil bear known as- Dave, ...
- UVA11309 Counting Chaos【Ad Hoc】
Wolfgang Puck's rival, Emeril Lagasse ("BAM!"), recently set the world culinary record in ...
- UVA11942 Lumberjack Sequencing【Ad Hoc】
Another tale of lumberjacks?. Let see - The lumberjacks are rude, bearded workers, while foremen ...
- UVA11764 Jumping Mario【Ad Hoc】
Mario is in the final castle. He now needs to jump over few walls and then enter the Koopa's Chamber ...
- POJ3359 UVA1209 LA3173 Wordfish【Ad Hoc】
Wordfish Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1082 Accepted: 535 Description Y ...
- POJ2940 HDU1489 UVA11054 Wine Trading in Gergovia【Ad Hoc】
Wine Trading in Gergovia Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3541 Accepte ...
- UVA344 UVALive5452 Roman Digititis【Ad Hoc】
Many persons are familiar with the Roman numerals for relatively small numbers. The symbols "i& ...
最新文章
- PHP和mysql的长连接
- 【Android 安全】DEX 加密 ( Application 替换 | ActivityThread 中的 mAllApplications 集合添加 Application )
- Codeforces 987A. Infinity Gauntlet(手速题,map存一下输出即可)
- varnish缓存服务器构建疑问
- linux nfs 修复文件,linux nfs Read-only file system
- mysql 3.5安装_MYSQL学习笔记-06-搭建数据库
- 【bzoj1705】[Usaco2007 Nov]Telephone Wire 架设电话线 dp
- Java自动生成增量补丁自动部署_Shell脚本结合Git实现增量项目部署
- Html数组下标访问帧,javaScript array(数组)使用字符串作为数组下标的方法
- python3修改文件的编码格式_python批量修改文件编码格式的方法
- 一套键鼠控制多台电脑操作——Synergy软件(windows环境)
- 通信 之 无线信道衰落
- 32位与64位CPU字长
- 语音论文优选:口语理解A Streaming End-to-End Framework For SLU
- VTK笔记-了解VTK
- 云服务器怎么安装虚拟主机,服务器上怎么安装虚拟主机
- 雨林木风 linux操作系统,“雨林木风”操作系统门户正式上线
- Spark中cache、persist、checkpoint区别
- x86_64汇编之三:x86_64汇编和x86_32汇编的区别
- 手机上测试空气质量的软件,PM2.5指数爆表:6款PM2.5手机查询软件实时监测空气质量...
热门文章
- 使用GDAL的MEM内存文件保存临时文件
- 详解微信小程序开发(项目从零开始)
- C#链接各种数据库代码总结
- mysql每一行数据类型_MySQL_MySQL编程中的6个实用技巧,每一行命令都是用分号(;)作为 - phpStudy...
- Qt error: collect2: error: ld returned 1 exit status
- 计算机软件系统课程导入,中学信息技术 计算机系统的组成课件 硬件软件导入恰当...
- 详解:Hive的存储格式与对比
- 在计算机里分数线怎么表示什么意思,高考投档分数线是什么意思 怎么定的
- Git教程——为什么要掌握Git以及Git的安装
- LeetCode 70.爬楼梯(动态规划)