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 |
写了1个小时的程序,却花了3个多小时都没发现错误,谁能帮我看一下程序,先谢了程序如下: #include<stdio.h> char data[]="ESWN"; int d[200],room[200][200],a,b,x[200],y[200]; int check(int k,int n) { int t,i; if(d[k]==1) { t=x[k]; for(i=1;i<=n;i++) { t++; if(t>a) return -1; if(room[y[k]][t]) return room[y[k]][t]; } room[y[k]][x[k]]=0; room[y[k]][t]=k; x[k]=t; return 0; } if(d[k]==2) { t=y[k]; for(i=1;i<=n;i++) { t--; if(t<=0) return -1; if(room[t][x[k]]) return room[t][x[k]]; } room[y[k]][x[k]]=0; room[t][x[k]]=k; y[k]=t; return 0; } if(d[k]==3) { t=x[k]; for(i=1;i<=n;i++) { t--; if(t<=0) return -1; if(room[y[k]][t]) return room[y[k]][t]; } room[y[k]][x[k]]=0; room[y[k]][t]=k; x[k]=t; return 0; } t=y[k]; for(i=1;i<=n;i++) { t++; if(t>b) return -1; if(room[t][x[k]]) return room[t][x[k]]; } room[y[k]][x[k]]=0; room[t][x[k]]=k; y[k]=t; return 0; } int main() { int i,j,k,n,m,N,t,s; char c; scanf("%d",&N); for(i=1;i<=N;i++) { scanf("%d %d",&a,&b); for(j=1;j<=b;j++) for(k=1;k<=a;k++) room[j][k]=0; scanf("%d %d",&n,&m); for(j=1;j<=n;j++) { scanf("%d %d %c",&x[j],&y[j],&c); room[y[j]][x[j]]=j; for(k=0;k<=3;k++) if(c==data[k]) break; d[j]=k+1; } for(j=1;j<=m;j++) { scanf("%d %c %d",&t,&c,&s); if(c=='L') { s%=4; d[t]-=s; if(d[t]<=0) d[t]+=4; } else if(c=='R') { s%=4; d[t]+=s; d[t]%=4; if(d[t]==0) d[t]=4; } else { k=check(t,s); if(k!=0) break; } } if(k==-1) printf("Robot %d crashes into the wall\n",t); else if(k==0) printf("OK\n"); else printf("Robot %d crashes into robot %d\n",t,k); for(k=j+1;k<=m;k++) scanf("%d %c %d",&t,&c,&s); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator