question: a rectangle, divided into a * B squares of the same size, set n A robot is placed in some small squares, giving them some instructions. They will step by step follow the instructions, and each time there is only one robot. If two robots are in the same small square, they will collide; if they are out of the border, they will hit the wall. The first collision state of the robot after some commands are output.
# Include <iostream> using namespace STD; int map [101] [101]; int A, B; struct Rob {int X, Y, Sid;} robot [101]; struct instruction {int ro_id, step; char point;} INS [101]; bool proccess (struct Instruction Act) {int I, id = act. ro_id; while (Act. step --) {If (Act. point = 1) robot [ID]. de = (robot [ID]. del + 1) % 4; else if (Act. point =-1) {robot [ID]. del-= 1; if (robot [ID]. del =-1) robot [ID]. de = 3;} el Se if (Act. point = 0) {map [robot [ID]. x] [robot [ID]. y] = 0; Switch (robot [ID]. len) {Case 0: robot [ID]. Y ++; break; Case 1: robot [ID]. X --; break; Case 2: robot [ID]. Y --; break; Case 3: robot [ID]. X ++; break;} If (robot [ID]. Y <1 | robot [ID]. x <1 | robot [ID]. x> A | robot [ID]. y> B) {cout <"robot" <id <"crashes into the wall" <Endl; return false;} else if (Map [robot [ID]. x] [robot [ID]. y]! = 0) {cout <"robot" <id <"crashes into robot" <map [robot [ID]. x] [robot [ID]. y] <Endl; return false;} map [robot [ID]. x] [robot [ID]. y] = ID ;}} return true;} int main () {char ch; int K, n, m; CIN> K; while (k --) {memset (MAP, 0, sizeof (MAP); memset (INS, 0, sizeof (INS); CIN> A> B; cin> N> m; int I; for (I = 1; I <= N; I ++) {CIN> robot [I]. x> robot [I]. y> CH; If (CH = 'n') robot [I]. de = 0; else I F (CH = 'W') robot [I]. del = 1; else if (CH ='s ') robot [I]. del = 2; else if (CH = 'E') robot [I]. DH = 3; Map [robot [I]. x] [robot [I]. y] = I ;}for (I = 1; I <= m; I ++) {CIN> INS [I]. ro_id> CH> INS [I]. step; If (CH = 'l') INS [I]. point = 1; else if (CH = 'R') INS [I]. point =-1; elseins [I]. point = 0 ;}for (I = 1; I <= m; I ++) {If (! Proccess (INS [I]) break;} if (I> m) cout <"OK" <Endl;} return 0 ;}