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 |
可以帮忙看看程序吗?不知道什么情况下出错...#include<iostream.h> using namespace std; int main() { int test; int len1,len2; int n,m,a,num,temp,flag; int x[102],y[102],who[102][102]; char state[102],d; bool s[102][102]; int i,j,d1[102],d2[102]; int robot1,robot2; cin>>test; while(test--) { cin>>len1>>len2>>n>>m; for(i=0;i<=len1+1;i++) for(j=0;j<=len2+1;j++) { s[i][j]=false; who[i][j]=0; } flag=0; robot1=0; robot2=0; for(i=1;i<=n;i++) { cin>>x[i]>>y[i]>>state[i]; s[x[i]][y[i]]=true; who[x[i]][y[i]]=i; if(state[i]=='E') { d1[i]=-1;//南北方向 d1=1,东西方向 d1=-1 d2[i]=1;//面向坐标增长方向 d2=1 否则d2=-1 } else { if(state[i]=='N') { d1[i]=1; d2[i]=1; } else { if(state[i]=='W') { d1[i]=-1; d2[i]=-1; } else { d1[i]=1; d2[i]=-1; } } } } for(i=0;i<m;i++) { cin>>a>>d>>num; if(flag==0) { if(d=='L'||d=='R') { if(d=='L'&&num%4==2 || d=='R'&&num%4==2 ) d2[a]=-d2[a]; else { if(d=='R'&&num%4==1 ||d=='L'&& num%4==3) { if(d1[a]==-1) d2[a]=-d2[a]; d1[a]=-d1[a]; } else { if(d=='R'&&num%4==3 ||d=='L'&& num%4==1) { if(d1[a]==1) d2[a]=-d2[a]; d1[a]=-d1[a]; } } } } else { if(d1[a]==-1) { temp=0; for(j=1;j<=num;j++) { temp+=d2[a]; if(x[a]+temp>len1 || x[a]+temp<1) { flag=1; robot1=a; break; } else { if(s[x[a]+temp][y[a]]==true) { flag=2; robot1=a; robot2=who[x[a]+temp][y[a]]; break; } } } if(j>num) { s[x[a]][y[a]]=false; who[x[a]][y[a]]=0; s[x[a]+temp][y[a]]=true; who[x[a]+temp][y[a]]=a; x[a]=x[a]+temp; } } else { temp=0; for(j=1;j<=num;j++) { temp+=d2[a]; if(y[a]+temp>len2) { flag=1; robot1=a; break; } else { if(s[x[a]][y[a]+temp]==true) { flag=2; robot1=a; robot2=who[x[a]][y[a]+temp]; break; } } } if(j>num) { s[x[a]][y[a]]=false; who[x[a]][y[a]]=0; s[x[a]][y[a]+temp]=true; who[x[a]][y[a]+temp]=a; y[a]+=temp; } } } } } if(flag==0) cout<<"OK"<<endl; else { if(flag==1) cout<<"Robot "<<robot1<<" crashes into the wall"<<endl; else cout<<"Robot "<<robot1<<" crashes into robot "<<robot2<<endl; } } system("pause"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator