#P6207. [USACO06OCT] Cows on Skates G

    ID: 6986 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>搜索2006USACOSpecial Judge广度优先搜索 BFS深度优先搜索 DFS

[USACO06OCT] Cows on Skates G

Problem Description

This problem uses a Special Judge.

Farmer John divided the farm into a matrix with rr rows and cc columns, and found that cows cannot pass through some areas. Now, Bessie is in the cell with coordinates (1,1)(1,1), and she wants to reach the barn at (r,c)(r,c) to enjoy dinner. She knows that starting from her current cell and moving each time to one of the four adjacent cells, there is always at least one path that can reach the barn.

There may be infinitely many such paths. Please output any one of them, and make sure the number of moves needed does not exceed 100000100000.

Input Format

The first line contains two integers r,cr, c.

The next rr lines each contain cc characters, indicating whether Bessie can pass through the corresponding cell. Each character is either . or *.

  • . means Bessie can pass through this cell.
  • * means Bessie cannot pass through this cell.

Output Format

Output several lines. Each line contains two integers separated by a space, representing the coordinates of the cells Bessie passes through in order.

Obviously, the first line of the output is 1 1, and the last line is r c.

The cells represented by two adjacent coordinates must be adjacent.

5 8
..*...**
*.*.*.**
*...*...
*.*.*.*.
....*.*.
1 1
1 2
2 2
3 2
3 3
3 4
2 4
1 4
1 5
1 6
2 6
3 6
3 7
3 8
4 8
5 8

Hint

Constraints

For 100%100\% of the testdata, 1r1131 \le r \le 113, 1c771 \le c \le 77.


Sample Explanation

The figure shows an illustration of a sample output. The answer is not unique.

Translated by ChatGPT 5