微前端架构如何改变企业的开发模式与效率提升
631
2022-08-31
sdut2410 Mine Number
Mine Number
Time Limit: 1000MS Memory limit: 65536K
题目描述
Every one once played the game called Mine Sweeping, here I change the rule. You are given an n*m map, every element is a '*' representing a mine, or a '.' representing any other thing. If I ask you what's the total number of mines around (i, j), you should check (i, j)'s up, down, left, right and also itself (if overstep the boundary, ignore it), if that position is a '*', you should add one to the total number of (i, j), and here I call the number Mine Number. For example, if the map is "..**.. ", we can get the Mine Number as "012210" easily, but here is the question, if I give you the Mine Number, can you tell me the original map?
输入
The input consists of multiple test cases. The first line contains a number T, representing the number of test cases. Then T lines follow. For each case, the first line contains two numbers n and m (1<=n, m<=20).representing the lines and rows. Then following n lines, each line contain m numbers each number represents the Mine Number.
输出
For each case, please print the case number (beginning with 1) and the original map which you reverted. The data guarantee there is only one result.
示例输入
27 11100101001012122322122232354532323323555323233123532133321022201333100010001115 6001110013431014541013431001110
示例输出
Case 1:...........*..*.*..*.**.*****.*.**.*****.*.**..***..*.**...*...***...........Case 2:........***...***...***.......
提示
来源
2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
上面的数字3,代表该点八个方向上有三颗雷。
这道题题意也差不多,只是数字所代表的是 上下左右与该点 五个方向的雷数量。
题目会给出数字,让你确定 雷的分布图,每个数据只输出一个解。
DFS,深度优先搜索。
大体的思路方向是:
从0,0开始往后判断,每个点是否放雷,依据就是周围的数字(上下左右)是否有0的情况,有0就不放雷。
放雷后就要将五个方向的数字减1,然后继续往后判断。
这是主要的判断,但是显然需要大的前提来 剪掉大半棵树。
→首先将第一行枚举,然后每一行根据上一行状态来做:
如果上一行同位置数字为0,则该点不放雷。
如果上一行同位置数字为1,则该点必须放雷,此时判断四周是否有0的情况,没有则放雷,有则回溯。
如果上一行同位置数字不为0或者1,则回溯。
判断到最后一行,需要将最后一行数组判断,是否全为0,是则输出结果,不是则回溯。
就是这样!
#include 不是很懂,尽量多刷题吧
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~