2015/1/25
題目本身不難,坑在圖的轉換(給你的a,b和座標不是拿來就能用的),圖轉換的同時別忘記座標系ENWS的位置也會變化就行
還有就是敲的時候情況都要考慮到,由於代碼敲得有點多,debug的時候會很煩。
= =像我就是debug後把各種測試輸出數據語句沒註釋掉。。
結果wa 7。
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<climits>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define mod 10007
#define lson pos<<1,l,mid
#define sc(n) scanf("%d",&n)
#define rson pos<<1|1,mid+1,r
#define pr(n) printf("%d\n",n)
#define met(n,m) memset(n, m, sizeof(n))
#define F(x,y,i) for(int i = x;i > y; i--)
#define f(x,y,i) for(int i = x;i < y; i++)
#define ff(x,y,i) for(int i = x;i <= y; i++)
#define FF(x,y,i) for(int i = x;i >= y; i--)
const int N=100500;
const int inf = INT_MAX;
int Max(int a,int b)
{
return a>b?a:b;
}
int Min(int a,int b)
{
return a<b?a:b;
}
int a, b;
int tp[4][2]={
0,1,
1,0,
0,-1,
-1,0
};
//zuo -1 ,you +1
struct node{
int x;
int y;
int turn;
}robot[1005];
struct edge{
int x;
int y;
char ch;
}ss[1005];
int vis[105][105];
int go(int s, int y)
{
int xx = robot[s].x;
int yy = robot[s].y;
int x1 = xx + y*tp[robot[s].turn][0];
int y1 = yy + y*tp[robot[s].turn][1];
// printf("%d %d %d %d\n",xx,yy,x1,y1);
// printf("%d %d\n",vis[xx][yy],vis[x1][y1]);
vis[xx][yy] = 0;
if(xx == x1)
{
if(y1 > b)
{
for(int i = yy;i <= b; i++)
{
if(vis[x1][i])
{
printf("Robot %d crashes into robot %d\n",s,vis[x1][i]);
return 1;
}
}
printf("Robot %d crashes into the wall\n",s);
return 1;
}
else if(y1 < 1)
{
for(int i = yy;i >= 1; i--)
{
if(vis[x1][i])
{
printf("Robot %d crashes into robot %d\n",s,vis[x1][i]);
return 1;
}
}
printf("Robot %d crashes into the wall\n",s);
return 1;
}
else
{
if(yy < y1)
{
for(int i = yy;i <= y1; i++)
{
if(vis[x1][i])
{
printf("Robot %d crashes into robot %d\n",s,vis[x1][i]);
return 1;
}
}
vis[x1][y1] = s;
robot[s].x=x1;
robot[s].y=y1;
return 0;
}
else
{
for(int i = yy;i >= y1; i--)
{
if(vis[x1][i])
{
printf("Robot %d crashes into robot %d\n",s,vis[x1][i]);
return 1;
}
}
vis[x1][y1] = s;
robot[s].x=x1;
robot[s].y=y1;
return 0;
}
}
}
else
{
if(x1 > a)
{
for(int i = xx;i <= a; i++)
{
if(vis[i][y1])
{
printf("Robot %d crashes into robot %d\n",s,vis[i][y1]);
return 1;
}
}
printf("Robot %d crashes into the wall\n",s);
return 1;
}
else if(x1 < 1)
{
for(int i = xx;i >= 1; i--)
{
if(vis[i][y1])
{
printf("Robot %d crashes into robot %d\n",s,vis[i][y1]);
return 1;
}
}
printf("Robot %d crashes into the wall\n",s);
return 1;
}
else
{
if(xx < x1)
{
for(int i = xx;i <= x1; i++)
{
if(vis[i][yy])
{
printf("Robot %d crashes into robot %d\n",s,vis[i][yy]);
return 1;
}
}
vis[x1][y1] = s;
robot[s].x=x1;
robot[s].y=y1;
return 0;
}
else
{
for(int i = xx;i >= x1; i--)
{
if(vis[i][yy])
{
printf("Robot %d crashes into robot %d\n",s,vis[i][yy]);
return 1;
}
}
vis[x1][y1] = s;
robot[s].x=x1;
robot[s].y=y1;
return 0;
}
}
}
return 0;
}
int main()
{
//freopen("data.txt", "r", stdin);
// freopen("data.in", "w", stdout);
int n, m, tot, x, y;
int cot = 0;
char ch;
while(~scanf("%d",&tot))
{
while(tot--)
{
cot++;
met(vis,0);
int temp = 1;
scanf("%d%d",&b,&a);
//if(cot==20)printf("%d %d\n",b,a);
scanf("%d%d",&n,&m);
// if(cot==20)printf("%d %d\n",n,m);
f(1,n+1,i)
{
scanf("%d%d%*c%c",&robot[i].y,&robot[i].x,&ch);
//if(cot==20)printf("%d %d %c\n",robot[i].y,robot[i].x,ch);
vis[robot[i].x][robot[i].y] = i;
if(ch=='E')robot[i].turn=0;
if(ch=='N')robot[i].turn=1;
if(ch=='W')robot[i].turn=2;
if(ch=='S')robot[i].turn=3;
}
f(0,m,i)
{
scanf("%d %c %d",&ss[i].x,&ss[i].ch,&ss[i].y);
// if(cot==20)printf("%d %c %d\n",ss[i].x,ss[i].ch,ss[i].y);
}
f(0,m,i)
{
x = ss[i].x;
ch = ss[i].ch;
y = ss[i].y;
if(ch=='L')
{
robot[x].turn=(robot[x].turn +y)%4;
}
else if(ch=='R')
{
robot[x].turn=(robot[x].turn + 3*y)%4;
}
else
{
if(go(x,y))
{
// printf("round %d \n",i+1);
temp = 0;
break;
}
}
}
if(temp)printf("OK\n");
}
}
return 0;
}