Q 1429: [2014 5th exam questions] Landon Ants
Time limit: 1Sec Memory Limit: 128MB
Title Description
The Langdon ant, which was introduced in 1986 by Chris Langdon, is a type of cellular automaton.
A square grid on a flat surface is filled with black or white. In one of the squares there is an “ant”. The ant’s head is oriented to one of the left and right sides.
The movement rule for ants is very simple: If the ant is in a black square, turn 90 degrees to the right, change the square to a white square, and move forward one square; If the ant is in the white frame, turn 90 degrees to the left, change the frame to black, and move one frame forward.
Although the rule is simple, the ant’s behavior is very complicated. The routes left at the beginning will be close to symmetrical and seem to repeat, but regardless of the starting state, the ants will open up a regular “highway” after a long period of chaotic activity.
The route of ants is very difficult to predict in advance.
Your task is to use a computer to simulate the position of the Langdon ants after the nth walk, based on the initial state.
Input
The first row of the input data is m n two integers (3 < m, n < 100), indicating the number of rows and columns of the square grid. This is followed by m rows of data. Each row of data is n numbers separated by spaces. 0 indicates a white cell and 1 indicates a black cell.
Next is a row of data: x y s k, where x y is an integer that represents the row and column numbers of the ants (row numbers grow from top to bottom, column numbers grow from left to right, both starting from 0). s is a capital letter that represents the orientation of the ants’ heads, and we agree to use: UDLR for top, bottom, left and right. k represents the number of steps taken by the ants.
Output
The output data is a space-separated integer p q, which represents the row and column numbers of the grid in which the ant is located after k steps, respectively.
Sample Input
|
|
Sample Output
|
|
C Code
Solution A
|
|
Solution B
|
|