#include <stdio.h>
#include <string.h>
typedef struct
{
int nX;
int nY;
char cDir;
}Robot_S;
int main()
{
int K;
Robot_S astRobots[100 + 1];
int anMap[100 + 1][100 + 1];
char cDirection[] = "NESW";
int anXYOffset[sizeof(cDirection)][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
scanf("%d", &K);
while (K--)
{
int A, B;
scanf("%d %d", &A, &B);
int N, M;
scanf("%d %d", &N, &M);
memset(anMap, 0, sizeof(anMap));
// Start from 1
for (int i = 1; i <= N; i++)
{
scanf("%d %d %c", &astRobots[i].nX, &astRobots[i].nY, &astRobots[i].cDir);
// Record robots
anMap[astRobots[i].nY][astRobots[i].nX] = i;
// Change direction format
for (int j = 0; j < (int)sizeof(cDirection); j++)
{
if (astRobots[i].cDir == cDirection[j])
{
astRobots[i].cDir = j;
break;
}
}
}
bool bCrashed = false;
for (int i = 0; i < M; i++)
{
int nIndex;
char cInstruction;
int nRepeat;
scanf("%d %c %d", &nIndex, &cInstruction, &nRepeat);
// continue to read instruction
if (bCrashed == true)
{
continue;
}
switch (cInstruction)
{
case 'R':
astRobots[nIndex].cDir = (astRobots[nIndex].cDir - nRepeat) % 4 + 4;
break;
case 'L':
astRobots[nIndex].cDir = (astRobots[nIndex].cDir + nRepeat) % 4;
break;
case 'F':
{
int nX = astRobots[nIndex].nX;
int nY = astRobots[nIndex].nY;
int nXOffset = anXYOffset[astRobots[nIndex].cDir][0];
int nYOffset = anXYOffset[astRobots[nIndex].cDir][1];
while (nRepeat--)
{
anMap[astRobots[nIndex].nY][astRobots[nIndex].nX] = 0;
astRobots[nIndex].nX += nXOffset;
astRobots[nIndex].nY += nYOffset;
if (astRobots[nIndex].nX < 1 || astRobots[nIndex].nX > A ||
astRobots[nIndex].nY < 1 || astRobots[nIndex].nY > B)
{
printf("Robot %d crashes into the wall\n", nIndex);
bCrashed = true;
break;
}
if (anMap[astRobots[nIndex].nY][astRobots[nIndex].nX] != 0)
{
printf("Robot %d crashes into robot %d\n", nIndex, anMap[astRobots[nIndex].nY][astRobots[nIndex].nX]);
bCrashed = true;
break;
}
anMap[astRobots[nIndex].nY][astRobots[nIndex].nX] = nIndex;
}
astRobots[nIndex].nX = nX;
astRobots[nIndex].nY = nY;
break;
}
default:
break;
}
}
if (false == bCrashed)
{
printf("OK\n");
}
}
return 0;
}
#include <string.h>
typedef struct
{
int nX;
int nY;
char cDir;
}Robot_S;
int main()
{
int K;
Robot_S astRobots[100 + 1];
int anMap[100 + 1][100 + 1];
char cDirection[] = "NESW";
int anXYOffset[sizeof(cDirection)][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
scanf("%d", &K);
while (K--)
{
int A, B;
scanf("%d %d", &A, &B);
int N, M;
scanf("%d %d", &N, &M);
memset(anMap, 0, sizeof(anMap));
// Start from 1
for (int i = 1; i <= N; i++)
{
scanf("%d %d %c", &astRobots[i].nX, &astRobots[i].nY, &astRobots[i].cDir);
// Record robots
anMap[astRobots[i].nY][astRobots[i].nX] = i;
// Change direction format
for (int j = 0; j < (int)sizeof(cDirection); j++)
{
if (astRobots[i].cDir == cDirection[j])
{
astRobots[i].cDir = j;
break;
}
}
}
bool bCrashed = false;
for (int i = 0; i < M; i++)
{
int nIndex;
char cInstruction;
int nRepeat;
scanf("%d %c %d", &nIndex, &cInstruction, &nRepeat);
// continue to read instruction
if (bCrashed == true)
{
continue;
}
switch (cInstruction)
{
case 'R':
astRobots[nIndex].cDir = (astRobots[nIndex].cDir - nRepeat) % 4 + 4;
break;
case 'L':
astRobots[nIndex].cDir = (astRobots[nIndex].cDir + nRepeat) % 4;
break;
case 'F':
{
int nX = astRobots[nIndex].nX;
int nY = astRobots[nIndex].nY;
int nXOffset = anXYOffset[astRobots[nIndex].cDir][0];
int nYOffset = anXYOffset[astRobots[nIndex].cDir][1];
while (nRepeat--)
{
anMap[astRobots[nIndex].nY][astRobots[nIndex].nX] = 0;
astRobots[nIndex].nX += nXOffset;
astRobots[nIndex].nY += nYOffset;
if (astRobots[nIndex].nX < 1 || astRobots[nIndex].nX > A ||
astRobots[nIndex].nY < 1 || astRobots[nIndex].nY > B)
{
printf("Robot %d crashes into the wall\n", nIndex);
bCrashed = true;
break;
}
if (anMap[astRobots[nIndex].nY][astRobots[nIndex].nX] != 0)
{
printf("Robot %d crashes into robot %d\n", nIndex, anMap[astRobots[nIndex].nY][astRobots[nIndex].nX]);
bCrashed = true;
break;
}
anMap[astRobots[nIndex].nY][astRobots[nIndex].nX] = nIndex;
}
astRobots[nIndex].nX = nX;
astRobots[nIndex].nY = nY;
break;
}
default:
break;
}
}
if (false == bCrashed)
{
printf("OK\n");
}
}
return 0;
}