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 |
像骑士巡游那样写个方向数组,不用枚举每种情况,看起来清楚,不容易出错In Reply To:提交10次了还是WrongAnswer,请各位大侠指正!!! Posted by:589742 at 2005-10-09 19:49:05 > #include <iostream> > #include <stdlib.h> > #include <string> > using namespace std; > #define N 0 > #define W 1 > #define S 2 > #define E 3 > #define F 0 > #define L 1 > #define R 2 > int main(int argc, char *argv[]) > { > int i,j,k,m=0,k0,k1,k2,m0,m1,m2,m3,flag; > int test,*length,*width; > int *number,*instr,(*pos)[100][4],(*action)[100][3],(*temp)[100][100]; > char s1,s2; > cin>>test; > length=new int[test];width=new int[test]; > number=new int[test];instr=new int[test];pos=new int[test][100][4]; > action=new int[test][100][3];temp=new int[test][100][100]; > for(m=0;m<test;m++){ > cin>>length[m]>>width[m]; > cin>>number[m]>>instr[m]; > for(i=1;i<=length[m];i++) > for(j=1;j<=width[m];j++) > temp[m][i][j]=0; > for(i=1;i<=number[m];i++){ > cin>>pos[m][i][0]>>pos[m][i][1]>>s1; > temp[m][pos[m][i][0]][pos[m][i][1]]=i; > pos[m][i][3]=i; > if(s1=='N') pos[m][i][2]=N; > else if(s1=='S') pos[m][i][2]=S; > else if(s1=='W') pos[m][i][2]=W; > else if(s1=='E') pos[m][i][2]=E; > } > for(j=1;j<=instr[m];j++){ > cin>>action[m][j][0]>>s2>>action[m][j][2]; > if(s2=='L') action[m][j][1]=L; > else if(s2=='R') action[m][j][1]=R; > else if(s2=='F') action[m][j][1]=F; > } > } > for(m=0;m<test;m++){ > for(i=1;i<=instr[m];i++){ > flag=2; > k0=action[m][i][0];k1=action[m][i][1];k2=action[m][i][2]; > m0=pos[m][k0][0];m1=pos[m][k0][1];m2=pos[m][k0][2]; > temp[m][m0][m1]=0; > if(k1==L){ > switch(k2%4){ > case 0: break; > case 1: pos[m][k0][2]=(m2+1)%4;break; > case 2: pos[m][k0][2]=(m2+2)%4;break; > case 3: pos[m][k0][2]=(m2+3)%4;break; > } > } > else if(k1==R){ > switch(k2%4){ > case 0: break; > case 1: pos[m][k0][2]=(m2+3)%4;break; > case 2: pos[m][k0][2]=(m2+2)%4;break; > case 3: pos[m][k0][2]=(m2+1)%4;break; > } > } > else if(k1==F){ > switch(m2){ > case N: > for(k=0;k<k2;k++){ > m1++; > if(m1>width[m]){ flag=1;break;} > else if(temp[m][m0][m1]!=0){ flag=0;break;} > pos[m][k0][1]=m1; > } > break; > case W: > for(k=0;k<k2;k++){ > m0--; > if(m0<1){ flag=1;break;} > else if(temp[m][m0][m1]!=0){ flag=0;break;} > pos[m][k0][0]=m0; > } > break; > case S: > for(k=0;k<k2;k++){ > m1--; > if(m1<1){ flag=1;break;} > else if(temp[m][m0][m1]!=0){ flag=0;break;} > pos[m][k0][1]=m1; > } > break; > case E: > for(k=0;k<k2;k++){ > m0++; > if(m0>length[m]){ flag=1;break;} > else if(temp[m][m0][m1]!=0){ flag=0;break;} > pos[m][k0][0]=m0; > } > break; > } > } > if(flag==2) { > temp[m][m0][m1]=k0; > } > else if(flag==1){ > cout<<"Robot "<<k0<<" crashes into the wall"<<endl; > break; > } > else if(flag==0){ > for(k=1;k<number[m];k++) > if((pos[m][k][0]==m0)&&(pos[m][k][1]==m1)) > break; > cout<<"Robot "<<k0<<" crashes into robot " > <<pos[m][k][3]<<endl; > break; > } > } > if((flag>1)&&(i>instr[m])) > cout<<"OK"<<endl; > } > delete[] length;delete[] width;delete[] number;delete[] instr; > delete[] pos[100][4];delete[] action[100][3];delete[] temp[100][100]; > 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