POJ-2632 Crashing Robots 模拟水题
题目链接:http://poj.org/problem?id=2632
模拟水题,直接循环判定即可。
1 //STATUS:C++_AC_0MS_212KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vector> 10 #include<queue> 11 #include<stack> 12 #include<map> 13 using namespace std; 14 #define LL __int64 15 #define pii pair<int,int> 16 #define Max(a,b) ((a)>(b)?(a):(b)) 17 #define Min(a,b) ((a)<(b)?(a):(b)) 18 #define mem(a,b) memset(a,b,sizeof(a)) 19 #define lson l,mid,rt<<1 20 #define rson mid+1,r,rt<<1|1 21 const int MAX=110,INF=0x3f3f3f3f,MOD=1999997; 22 const LL LLNF=0x3f3f3f3f3f3f3f3fLL; 23 24 struct Node{ 25 int x,y,r; 26 }nod[MAX]; 27 28 int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0}; 29 char ma[128]; 30 int g[MAX][MAX]; 31 int T,w,h,n,m,ans1,ans2; 32 33 int main() 34 { 35 // freopen("in.txt","r",stdin); 36 int i,j,a,b,ans,dir,nx,ny; 37 char s[2]; 38 ma['N']=0,ma['E']=1,ma['S']=2,ma['W']=3; 39 scanf("%d",&T); 40 while(T--){ 41 ans=0; 42 mem(g,0); 43 scanf("%d%d%d%d",&w,&h,&n,&m); 44 for(i=1;i<=n;i++){ 45 scanf("%d%d%s",&nod[i].x,&nod[i].y,s); 46 g[nod[i].x][nod[i].y]=i; 47 nod[i].r=ma[s[0]]; 48 } 49 for(i=0;i<m;i++){ 50 scanf("%d%s%d",&a,s,&b); 51 if(s[0]=='F'){ 52 dir=nod[a].r; 53 while(b--){ 54 nx=nod[a].x+dx[dir]; 55 ny=nod[a].y+dy[dir]; 56 if(nx<1 || nx>w || ny<1 || ny>h){ 57 ans=1;ans1=a; 58 break; 59 } 60 if(g[nx][ny]){ 61 ans=2;ans1=a;ans2=g[nx][ny]; 62 break; 63 } 64 g[nod[a].x][nod[a].y]=0; 65 g[nx][ny]=a; 66 nod[a].x=nx,nod[a].y=ny; 67 } 68 } 69 else if(s[0]=='L') 70 nod[a].r=(nod[a].r-b%4+4)%4; 71 else nod[a].r=(nod[a].r+b)%4; 72 if(ans)break; 73 } 74 for(i++;i<m;i++) 75 scanf("%d%s%d",&a,s,&b); 76 77 if(!ans)printf("OK\n"); 78 else if(ans==1)printf("Robot %d crashes into the wall\n",ans1); 79 else printf("Robot %d crashes into robot %d\n",ans1,ans2); 80 } 81 return 0; 82 }