Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WA细节,数组大小之前开的100结果wa,改成101 AC~#include<stdio.h> #include<stdlib.h> #include<string.h> int map[101][101]={0};//记录实时信息 int x[101],y[101];//第I个机器人的坐标 int fir[101]={0};//第I个机器人方向 int i,j,x1,x2,robot,repeat,k; char action,c; int t,a,b,m,n,bol; int change(char c){ if(c=='N') return 0; else if(c== 'E') return 1; else if(c== 'S' ) return 2; else if (c=='W') return 3; else return -1; }// N,E,S,W用0,1,2,3表示 int go(int rob,int x1,int y1){ map[x[rob]][y[rob]]=0; x[rob]+=x1; y[rob]+=y1; if(x[rob]==0 ||x[rob]==a+1 || y[rob]==0|| y[rob]==b+1) {bol=1;printf("Robot %d crashes into the wall\n",rob);} else if(map[x[rob]][y[rob]]!=0) {bol=1;printf("Robot %d crashes into robot %d\n",rob,map[x[rob]][y[rob]]);} else map[x[rob]][y[rob]]=rob;//动态更新MAP return 0; } int fun(int rob,char act,int rep){ int i,x,y; for(i=1;i<=rep;i++){ if(bol==1 ) return 0;//检测是否输出完毕 if(act=='L') fir[rob]=(fir[rob]+3)%4; else if(act=='R') fir[rob]=(fir[rob]+1)%4; else if(act=='F') { switch(fir[rob]){ case 0: go(rob,0,1);break; case 1: go(rob,1,0);break; case 2: go(rob,0,-1);break; case 3: go(rob,-1,0);break; defaolt: break; } } else ; } return 0; } int main(){ scanf("%d",&t); while(t--){ memset(map,0,100*100*sizeof(int)); memset(fir,0,100*sizeof(int)); memset(x,0,100*sizeof(int)); memset(y,0,100*sizeof(int)); scanf("%d %d",&a,&b); scanf("%d %d",&n,&m); for(i=1;i<=n;i++) {scanf("%d %d %c",&x1,&x2,&c);fir[i]=change(c);map[x1][x2]=i;x[i]=x1;y[i]=x2;} bol=0;//函数输出检测 for(i=1;i<=m;i++){ scanf("%d %c %d",&robot,&action,&repeat); fun(robot,action,repeat); } if(bol==0 ) printf("OK\n"); } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator