#abc295b. B - Bombs
B - Bombs
Score : points
问题描述
我们有一个棋盘,其横向有 行,纵向有 列。令 表示从上数第 行、从左数第 列的方格。
你被赋予了一些字符 ,它们代表了当前 方格的状态。.
表示一个空方格;#
表示一个带有墙壁的方格;1
, 2
,, 9
分别表示带有威力为 的炸弹的方格。
在下一时刻,所有炸弹将会同时爆炸。当一颗炸弹爆炸时,所有与该炸弹所在方格的曼哈顿距离不大于炸弹威力的方格都将变成空方格。这里,从方格 到 的曼哈顿距离定义为 。
请打印出爆炸后棋盘的状态。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a board with rows running horizontally and columns running vertically. Let denote the square at the -th row from the top and -th column from the left.
You are given characters representing the current states of . .
represents an empty square; #
represents a square with a wall; 1
, 2
,, 9
represent a square with a bomb of power , respectively.
At the next moment, all bombs will explode simultaneously. When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square. Here, the Manhattan distance from to is .
Print the board after the explosions.
Constraints
- and are integers.
- Each is one of
.
,#
,1
,2
, ,9
.
Input
The input is given from Standard Input in the following format:
Output
Print lines representing the board after the explosions. Use the format used in the input (do not print or ).
Sample Input 1
4 4
.1.#
###.
.#2.
#.##
Sample Output 1
...#
#...
....
#...
- The explosion of the bomb at will turn the blue squares and purple squares in the above figure into empty squares.
- The explosion of the bomb at will turn the red squares and purple squares in the above figure into empty squares.
As seen in this sample, the explosion ranges of bombs may overlap.
Sample Input 2
2 5
..#.#
###.#
Sample Output 2
..#.#
###.#
There may be no bombs.
Sample Input 3
2 3
11#
###
Sample Output 3
...
..#
Sample Input 4
4 6
#.#3#.
###.#.
##.###
#1..#.
Sample Output 4
......
#.....
#....#
....#.
update @ 2024/3/10 12:15:48