恶心的模拟题,敲错了字符,错了……
/*
* Author: stormdpzh
* POJ: 2632 Crashing Robots
* Time: 2012/5/12 12:02:49
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, a, b) for(int i = a; i >= b; i--)
#define out(n) printf("%d\n", n)
#define wh(n) while(scanf("%d", &n) != EOF)
#define whz(n) while(scanf("%d", &n) != EOF && n != 0)
#define lint long long
using namespace std;
const int MaxR = 105;
struct Robot {
int x, y;
int dir;
} robot[MaxR];
int n, m;
int a, b;
int kind, rno;
bool flag;
void getPlace(int *xx, int *yy, int id)
{
if(robot[id].dir == 0) {
*xx = robot[id].x + 1;
*yy = robot[id].y;
}
else if(robot[id].dir == 1) {
*xx = robot[id].x;
*yy = robot[id].y + 1;
}
else if(robot[id].dir == 2) {
*xx = robot[id].x - 1;
*yy = robot[id].y;
}
else if(robot[id].dir == 3) {
*xx = robot[id].x;
*yy = robot[id].y - 1;
}
}
int check(int xx, int yy)
{
repf(i, 1, n) {
if(robot[i].x == xx && robot[i].y == yy)
return i;
}
return 0;
}
void solve()
{
int no, times;
char opt;
int tmpx, tmpy;
rep(i, m) {
cin >> no >> opt >> times;
if(!flag) rep(j, times) {
switch(opt) {
case 'L':
robot[no].dir = (robot[no].dir + 1) % 4;
break;
case 'R':
robot[no].dir = (4 + robot[no].dir - 1) % 4;
break;
case 'F':
getPlace(&tmpx, &tmpy, no);
if(tmpx < 1 || tmpx > a || tmpy < 1 || tmpy > b) {
kind = 0;
rno = no;
flag = true;
}
else {
int res = check(tmpx, tmpy);
if(res > 0) {
flag = true;
rno = no;
kind = res;
}
else {
robot[no].x = tmpx;
robot[no].y = tmpy;
}
}
break;
}
if(flag) break;
}
}
}
int main()
{
int t;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &a, &b);
scanf("%d%d", &n, &m);
repf(i, 1, n) {
char d;
cin >> robot[i].x >> robot[i].y >> d;
if(d == 'E') robot[i].dir = 0;
else if(d == 'N') robot[i].dir = 1;
else if(d == 'W') robot[i].dir = 2;
else if(d == 'S') robot[i].dir = 3;
}
flag = false;
kind = -1;
solve();
if(kind == -1)
printf("OK\n");
else if(kind == 0)
printf("Robot %d crashes into the wall\n", rno);
else
printf("Robot %d crashes into robot %d\n", rno, kind);
}
return 0;
}