#CT0000127. Robot (Robot)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Robot (Robot)
Robot
Source: Bộ Giáo dục và Đào tạo
Version: Phuoc Hung OJ Extended
Problem Statement
Tuan built a robot for a maze-escaping competition. The robot continuously moves straight forward at metre per second. When the cell immediately ahead is blocked, it repeatedly turns to the left until the cell in front is free, then resumes moving. Turns take zero time, and the robot never stops on its own.
The floor is an infinite-looking grid of metre cells. Columns increase from left to right and rows from top to bottom; their indices range from to . The cell at column , row has coordinates . The maze occupies an subgrid with top-left cell . Some cells contain obstacles #, while . denotes an empty cell. There are no obstacles outside the maze.
Initially the robot stands at facing upwards. Its initial cell is unblocked and has at least one adjacent unblocked cell. Both its starting and final cells may lie outside the maze. Determine its coordinates after exactly seconds.
Input
- The first line contains four integers .
- Each of the next lines contains exactly characters
#or., describing one maze row in top-to-bottom order.
Output
Print two integers, the final and coordinates after seconds, separated by a space.
Subtasks
- Subtask 1 (50 points): ; ; ; each maze row contains characters from
#,.; the starting cell and at least one adjacent cell are unblocked. - Subtask 2 (50 points): ; ; ; each maze row contains characters from
#,.; the starting cell and at least one adjacent cell are unblocked.
Examples
Example 1
Input
4 3 5 9
###.
#...
#..#
##.#
Output
2 3
Explanation: The robot starts at , outside the maze. It turns left whenever a blockage is ahead and continues moving. Its coordinates after seconds through are , , , , , , , and . Thus its location after seconds is .
Example 2
Input
3 2 5 7
###
#..
#..
Output
2 6
Explanation: The robot starts at and successively reaches , , , , , , and after seconds through . The last cell is outside the maze.
Liên quan
Trong các cuộc thi sau: