又见模拟。。。。
注意一下方向,注意一下标记哪个机器人在哪个位置。
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct list
{
int x;
int y;
int way;
}rebort[10000];
int m,n;
int map[500][500];
int xi[4]={0,1,0,-1};
int yi[4]={1,0,-1,0};
int leap1,leap2;
int zhou(int a,int b)
{
int x,y,z;
x=rebort[a].x;
y=rebort[a].y;
z=rebort[a].way;
map[x][y]=0;
while(b--)
{
x+=xi[z];
y+=yi[z];
if(x>n||x<=0||y>m||y<=0)
{
leap1=a;
return 1;
}
if(map[x][y])
{
leap1=a;
leap2=map[x][y];
return 2;
}
}
map[x][y]=a;
rebort[a].x=x;
rebort[a].y=y;
return 0;
}
int put(int a,char c,int b)
{
if(c=='F')
{
if(zhou(a,b))return zhou(a,b);
}
else if(c=='L')
{
rebort[a].way=(rebort[a].way-b+400000)%4;
}
else if(c=='R')
{
rebort[a].way=(rebort[a].way+b)%4;
}
return 0;
}
int main()
{
int T,x,y,i,a,b,leap,j;
char c;
scanf("%d",&T);
while(T--)
{
memset(map,0,sizeof(map));
scanf("%d%d",&n,&m);
scanf("%d%d",&x,&y);
for(i=1;i<=x;i++)
{
scanf("%d%d %c",&a,&b,&c);
rebort[i].x=a;
rebort[i].y=b;
if(c=='N')leap=0;
else if(c=='E')leap=1;
else if(c=='S')leap=2;
else if(c=='W')leap=3;
rebort[i].way=leap;
map[a][b]=i;
}
for(i=1;i<=y;i++)
{
scanf("%d %c %d",&a,&c,&b);
leap=put(a,c,b);
if(leap)
break;
}
for(j=i+1;j<=y;j++)
{
scanf("%d %c %d",&a,&c,&b);
}
if(i==y+1)printf("OK\n");
else
{
if(leap==1)
printf("Robot %d crashes into the wall\n",leap1);
else if(leap==2)
printf("Robot %d crashes into robot %d\n",leap1,leap2);
}
}
return 0;
}