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 |
Re:代码能过各种样例,为何还是WA,求大神检查In Reply To:代码能过各种样例,为何还是WA,求大神检查 Posted by:zxy021222 at 2018-05-20 15:22:24 > #include<iostream> > #include<queue> > #include<string.h> > using namespace std; > int c,n,m; > int book[101][101][101]; > char mp[101][101][101]; > int dx[4]={0,0,1,-1}; > int dy[4]={1,-1,0,0}; > struct node{ > int x; > int y; > int f; > int step; > }; > int main(){ > while(cin>>c>>n>>m){ > if(c==0&&n==0&&m==0){ > break; > } > > queue<node> q; > int i,j,k,sf,sx,sy,ef,ex,ey; > for(i=1;i<=c;i++){ > for(j=1;j<=n;j++){ > for(k=1;k<=m;k++){ > cin>>mp[i][j][k]; > if(mp[i][j][k]=='S'){ > sf=i; > sx=j; > sy=k; > } > if(mp[i][j][k]=='E'){ > ef=i; > ex=j; > ey=k; > mp[i][j][k]='.'; > } > } > } > } > node start; > start.f=sf; > start.step=0; > start.x=sx; > start.y=sy; > q.push(start); > book[sf][sx][sy]=1; > while(q.empty()==false){ > node se=q.front(); > q.pop(); > for(i=0;i<=3;i++){ > int xx=se.x+dx[i]; > int yy=se.y+dy[i]; > if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&book[se.f][xx][yy]==0&&mp[se.f][xx][yy]=='.'){ > node newp; > newp.f=se.f; > newp.step=se.step+1; > newp.x=xx; > newp.y=yy; > book[se.f][xx][yy]=1; > q.push(newp); > if(newp.f==ef&&newp.x==ex&&newp.y==ey){ > cout<<"Escaped in "<<newp.step<<" minute(s)."<<endl; > break; > } > } > } > > node newp; > newp.f=se.f-1; > newp.step=se.step+1; > newp.x=se.x; > newp.y=se.y; > if(newp.f>=1&&book[newp.f][newp.x][newp.y]==0&&mp[newp.f][newp.x][newp.y]=='.'){ > book[newp.f][newp.x][newp.y]=1; > q.push(newp); > if(newp.f==ef&&newp.x==ex&&newp.y==ey){ > cout<<"Escaped in "<<newp.step<<" minute(s)."<<endl; > break; > } > } > > node newp2; > newp2.f=se.f+1; > newp2.step=se.step+1; > newp2.x=se.x; > newp2.y=se.y; > if(newp2.f<=c&&book[newp2.f][newp2.x][newp2.y]==0&&mp[newp2.f][newp2.x][newp2.y]=='.'){ > book[newp2.f][newp2.x][newp2.y]=1; > q.push(newp2); > if(newp2.f==ef&&newp2.x==ex&&newp2.y==ey){ > cout<<"Escaped in "<<newp2.step<<" minute(s)."<<endl; > break; > } > } > } > > if(q.empty()==true) > cout<<"Trapped!"<<endl; > > memset(book,0,sizeof(book)); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator