#include <stdio.h> #include <string.h> #include <conio.h> #define N 103 struct position { int x; //横的 int y; //竖的 int dir; //东南西北依次为1234 }pos[N]; int t, n, m, A, B; int f(char c) { switch(c) { case'E': return 1; case'S': return 2; case'W': return 3; case'N': return 4; } } int mark[N]; int isexit(struct position r) { int i; for(i=1; i<=n; i++) { if(! mark[i] && r.x == pos[i].x && r.y == pos[i].y) return i; } return 0; }
int isout(struct position r) { if(r.x <= 0 || r.x > A || r.y <=0 || r.y > B) return 1; else return 0; }
int main() { int i, j, k, bad; int a, b;
char c; freopen("in.txt", "r", stdin); scanf("%d", &t); while(t--) { scanf("%d%d%d%d", &A, &B, &n, &m); memset(pos, 0, sizeof(pos)); for(i=1; i<=n; i++) { scanf("%d%d %c", &a, &b, &c); pos[i].x = a; pos[i].y = b; pos[i].dir = f(c); } bad = 0; for(i=1; i<=m; i++) { scanf("%d %c%d", &a, &c, &b); if(!bad) { switch(c) { case 'F': for(j=1; j<=b; j++) //如果是前进的指令,要走一步看一步 { if(pos[a].dir == 1) pos[a].x ++; else if(pos[a].dir == 2) pos[a].y --; else if(pos[a].dir == 3) pos[a].x --; else pos[a].y ++; mark[a] = 1; if(k = isexit(pos[a])) //是否有机器人已经在这个位置了 { printf("Robot %d crashes into robot %d\n", a, k); bad = 1; break; } mark[a] = 0; if(isout(pos[a])) //是否出界了 { printf("Robot %d crashes into the wall\n", a); bad = 1; break; } } break; case 'L': for(j=1; j<=b; j++) //左转b次 { pos[a].dir = (pos[a].dir-1) % 4; if(pos[a].dir == 0) pos[a].dir = 4; } break; case'R': for(j=1; j<=b; j++) //右转b次 { pos[a].dir = (pos[a].dir+1) % 4; if(pos[a].dir == 0) pos[a].dir = 4; } break; } } } if(!bad) printf("OK\n"); } getch(); return 0; }
|