Chocobo World
Time Limit: 1 Second Memory Limit: 32768 KB
Biko is a baby chocobo. One day, his friend Mog (a cat) disappreared while looking for treasure. Thus Biko started searching for Mog with Catanus (a cactus) and Moomba (a monkey-like animal). Though they were partners, Catanus and Moomba were only responsible for finding weapons and items every now and then, Biko had to adventure on his own.
Chocobo World is a SOLO-RPG which means that the game can run automatically without being controled by players. Biko can walk, fight and sleep all by himself.
The game is played on a map of N*N grids which is shown by the above image
in the middle. The point which blinks is where Biko is. The other points represent
places of events. An event can be a battle, an item, a weapon or plot. Events
that are touched off no longer exist. The game system employs the following
method to make the game advance on it's own. The player first assign a value
m to MOVE in the menu. Then every time Biko enters a grid, he first checks m
grids ahead, to the left and to the right of himself. If there's no events in
these grids, he will keep his direction. Or if there's any event(s) going on,
Biko will turn to the direction where the nearest one is. If there are more
than one possible choices, he will select by the priority order moving ahead
> turning left > turning right. For example, in the map above, if m =
5Biko's initial direction is to the right. He goes to right 3, up 3, right
1, down 2, etc.
Now given N,m,and places of l events, output the order that Biko touches them
off.
Input
Input contains several tests. Each test has 3 intergers on its first line: N (N <= 100)m (m >= 0) and l(l <= 1000). The jth of the following l lines contain the x, y coordinates of the jth event. The upper left corner is (1 1), x axis points down and y axis points right. Any two events do no overlap. The following line has 2 integers x0 and y0 (1 <= x0, y0 <= N) represents the initial positon of Biko, where there is always no events. Biko always faces east at the beginning. Input is terminated with N = m = l = 0.
Output
A line for each case,output the events Biko touched off in the order he did.
Two adjacent numbers are seperated by a space. No spaces at the end of line.
P.S. The left side and the right side of the map are connected, so are the top
border and the bottom border.
Sample Input
18 5 8 1 18 7 12 8 11 8 18 9 12 13 8 14 13 14 14 10 8 0 0 0
Sample Output
3 2 5 6 4 1 8 7Submit
Source: ZOJ Monthly, March 2003