#abc311d. D - Grid Ice Floor
D - Grid Ice Floor
Score : points
问题描述
存在一个 的网格,以及一名站在上面的玩家。
令 表示该网格从上数第 行、从左数第 列的方格。
该网格中每个方格为冰或石,由 个长度为 的字符串 表示如下:
- 如果 的第 个字符是
.
, 方格 是冰; - 如果 的第 个字符是
#
, 方格 是石。
该网格的外周(所有位于第 行、第 行、第 列、第 列的方格)均为石。
初始时,玩家停留在冰方格 上。
玩家可以进行以下移动零次或多次。
- 首先,指定移动方向:向上、向下、向左或向右。
- 然后,按照指定方向持续移动,直到碰到岩石为止。正式表述为:
- 如果沿移动方向的下一个方格为冰,进入该方格并继续移动;
- 如果沿移动方向的下一个方格为石,留在当前方格并停止移动。
请计算玩家能够接触到(经过或停留于)的冰方格数量。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is an grid and a player standing on it.
Let denote the square at the -th row from the top and -th column from the left of this grid.
Each square of this grid is ice or rock, which is represented by strings of length as follows:
- if the -th character of is
.
, square is ice; - if the -th character of is
#
, square is rock.
The outer periphery of this grid (all squares in the -st row, -th row, -st column, -th column) is rock.
Initially, the player rests on the square , which is ice.
The player can make the following move zero or more times.
- First, specify the direction of movement: up, down, left, or right.
- Then, keep moving in that direction until the player bumps against a rock. Formally, keep doing the following:
- if the next square in the direction of movement is ice, go to that square and keep moving;
- if the next square in the direction of movement is rock, stay in the current square and stop moving.
Find the number of ice squares the player can touch (pass or rest on).
Constraints
- is a string of length consisting of
#
and.
. - Square is rock if , , , or .
- Square is ice.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
6 6
######
#....#
#.#..#
#..#.#
#....#
######
Sample Output 1
12
For instance, the player can rest on by moving as follows:
- .
The player can pass by moving as follows:
- , passing in the process.
The player cannot pass or rest on .
Sample Input 2
21 25
#########################
#..............###...####
#..............#..#...###
#........###...#...#...##
#........#..#..#........#
#...##...#..#..#...#....#
#..#..#..###...#..#.....#
#..#..#..#..#..###......#
#..####..#..#...........#
#..#..#..###............#
#..#..#.................#
#........##.............#
#.......#..#............#
#..........#....#.......#
#........###...##....#..#
#..........#..#.#...##..#
#.......#..#....#..#.#..#
##.......##.....#....#..#
###.............#....#..#
####.................#..#
#########################
Sample Output 2
215
update @ 2024/3/10 08:50:50