Robot Motion
Time Limit:1000 MS |
|
Memory Limit:10000 K |
Total Submissions:10219 |
|
Accepted:4977 |
Description
A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The pZ environment? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> usage + Ck4gbm9ydGggKHVwIHRoZSBwYWdlKSA8YnI + usage =" pst "> Input
There will be one or more grids for robots to navigate. the data for each is in the following form. on the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. the possible entry columns are numbered starting with one at the left. then come the rows of the direction instructions. each grid will have at least one and at most 10 rows and columns of instructions. the lines of instructions contain only the characters N, S, E, or W with no blanks. the end of input is indicated by a row containing 0 0.
Output
For each grid in the input there is one line of output. either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. the sample input below corresponds to the two grids above and below strates the two forms of output. the word "step" is always immediately followed by "(s)" whether or not the number before it is 1.
Sample Input
3 6 5NEESWEWWWESSSNWWWW4 5 1SESWEEESNWNWEENEWSEN0 0 0
Sample Output
10 step(s) to exit3 step(s) before a loop of 8 step(s)
Source
Mid-Central USA 1999
Http://poj.org/problem? Id = 1573
// Determine whether a loop is formed. Based on the characteristics of the question, you can set a tag array. If it passes through, it cannot go until the loop is exited.
Represent the number of steps to this coordinate with another array. When you exit the loop, you have actually reached the previous point and output the number of steps. Then, the loop section shows the total number of steps minus the current number of steps.
# Include
# Include
Int main () {int n, m, k, l, p, step; char s [11] [11]; int map [11] [11]; while (scanf ("% d", & n, & m )! = EOF) {if (n = 0 | m = 0) break; scanf ("% d", & k); for (int I = 0; I
= 0 & l
= 0 & p