Subject: Http://pj.org/Debug id=1573
Main idea: The board is full of n,e,s,w instructions. People follow the board's instructions to move from the initial column in the North until you finish chess or go around.
n Means moving north (UP).
E means moving eastward (right).
s means to move south (down).
W means moving Westward (left).
Analysis: Because the chessboard is only 10*10, that is, up to 100 steps, you can use the simulation algorithm. We declare a spell card mapping used to record instructions, and an initial value of zero for chess cards to record the path that has been traversed. Chess game or discovery path is not 0.
The code is as follows:
including Lt;stdio. HGT, including Lt;stdio. Include: ELT; strings. Hgt # define online void online () {# # # # #ifdef Online # # # # # # # Else Freopen (1573.in, R, stdin), Freopen (1573.out, W, stdout ); # #end If}const int LEN = 11; int R, c, s; Char map {len} {len} {len}} {len}; int {Len}} {path} {len} steps}, int int////; Simulation/loops/loops/; Freopen (1573.in,r,stdin s{if (x lt;=) 0x gt;r y lt;==0y gt;==0y gt;==0y gt;==0y gt;==0y gt;==0y gt;==0y gt;==0;c) {step=s;. =.=path{x}{y}!= 0 {steps = path {x} {y} {y}-1; loops = s-steps; return;} path {x} {x} {y} {y}}} = S + 1; if (map {x} {y}} = = N) {imitate (x-1, y, path {x} {x} {x} {x} {x} {x} {y} {x} {x} {y} {y} {y} {y} {{{}}}}} E if (map {x} {y} = = W) {imitate (x, y-1, path {x} {x} {y}} {y}}}); else if (map {x} {y} {y} ================================-1, path {x} {y}}}}} /////print void print print print () {{{{{{{{{{{{{{{{{{============-1}} {printf (% D step (s) to exit Prinn, before Step s); else else else TF (%D Step (% step (s) a) loop loop loop (% {scanf (% d% d% d N, R, c,if (r = = 0 c = = 0 C = = 0 S = = 0 S = = = 0) {break ; for (int I = 1; I lt; = = R; I + +) {for (int J = 1; J lt; = = C; J + + + {{{scanf (% c, map {i} {J}}}}}); ///End for J scanf (read (); return 0;} runthe results as follows:
1573 accepts 176K 0MS c+1414b 2011-0802 22:3,630
69 Chess game Source, POJ 1573 Robot Motion Simulation