MicrosoftOA #13
Cleaning Robot
估计中等可在线判题
考点(AI 标注)模拟/实现网格搜索
The robot starts at the top-left corner facing right. If the cell in front of it is empty, it moves forward; otherwise it turns 90 degrees clockwise in place. This repeats forever. Every empty cell it passes through counts as cleaned, and cells may be passed through repeatedly. Find the number of distinct cleaned cells after it runs indefinitely.
输入格式
The first line contains N M (1..1000), followed by N strings of length M, where . is an empty cell and X is an obstacle; the start (0,0) is guaranteed to be empty.
输出格式
Output a single integer, the answer.
样例 1
输入:
3 6
...X..
....XX
..X...
输出:
6
样例 2
输入:
1 1
.
输出:
1
样例 3
输入:
1 4
....
输出:
4
样例说明
Example 1: the robot loops along the boundary of the reachable two rows and three columns, cleaning 6 distinct cells in total.
Example 2: it is blocked on all four sides and only turns in place, cleaning its single cell; the answer is 1.
Example 3: it can keep moving back and forth along the same row, so all 4 cells are cleaned.