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 |
Why Wa?#include<iostream> #include<queue> #include<string.h> using namespace std; struct node { int x,y,z,step; }c,f; int n; int startx,starty,startz; int endx,endy,endz; char map[12][12][12]; int v[12][12][12]; int total[12][12][12]; int move[6][3]={{-1,0,0},{1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}}; queue<node>a; bool isok(int a,int b,int c) { if(a>=0&&a<n&&b>=0&&b<n&&c>=0&&map[a][b][c]=='O') return true; else return false; } int bfs() { c.x=startx; c.y=starty; c.z=startz; c.step=0; v[startx][starty][startz]=1; a.push(c); if(startx==endx&&starty==endy&&startz==endz) return 0; while(!a.empty()) { c=a.front(); if(c.x==endx&&c.y==endy&&c.z==endz) { return c.step ; } a.pop(); int i; for(i=0;i<6;i++) { int sx,sy,sz; sx=c.x+move[i][0]; sy=c.y+move[i][1]; sz=c.z+move[i][2]; /* if(sx==endx&&sy==endy&&sz==endz) return c.step+1;*/ if(isok(sx,sy,sz)&&!v[sx][sy][sz]) { if(sx==endx&&sy==endy&&sz==endz) return (c.step+1); f.x=sx; f.y=sy; f.z=sz; f.step=c.step+1; v[sx][sy][sz]=1; a.push(f); } } } return -1; } int main() { char s[9]; while(cin>>s>>n) { int i,j,k; for(i=0;i<n;i++) { for(j=0;j<n;j++) { for(k=0;k<n;k++) { cin>>map[k][j][i]; } getchar(); } } cin>>starty>>startx>>startz; cin>>endy>>endx>>endz>>s; map[endx][endy][endz]='O'; memset(v,0,sizeof(v)); while(!a.empty()) a.pop(); int ans=bfs(); if(ans!=-1) cout<<n<<" "<<ans<<endl; else cout<<"NO ROUTE"<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator