Question link: Click the open link
Question:
Each vertex has a robot (.). The following are some commands. Every time an instruction (a letter) is sent, all robots will execute the movement.
The robot will leave when it reaches the e-point.
If the robot is '#' or the boundary is in place. One square can stand for multiple robots.
Bitset simulation ..
# Include <cstdio> # include <cstring> # include <algorithm> # include <bitset> using namespace STD; char s [100005]; int n, m, K; int work () {bitset <23000> A, B, C, E; For (INT I = 0; I <n; I ++) {scanf ("% s ", s); For (Int J = 0; j <m; j ++) {(s [J] = '#'? B: A). Set (I * m + J); (s [J] = 'e '? E. set (I * m + J): 0) ;}} scanf ("% s", S); C = A; For (INT I = 0; I <K; I ++) {If (C = e) return I; If (s [I] = 'U') C = (C> m) &) | (C & (B <m); If (s [I] = 'l') C = (C> 1) &) | (C & (B <1); If (s [I] = 'D') C = (C <m) &) | (C & (B> m); If (s [I] = 'R') C = (C <1) &) | (C & (B> 1) ;}if (C = e) return K; Return-1 ;}int main () {int I, J; while (~ Scanf ("% d", & N, & M, & K) {printf ("% d \ n", work ());} return 0 ;}