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:xyz的顺序弄错了,全用zxy的顺序 2:改了两个判断条件In Reply To:怎么一直wa啊,求指点 Posted by:zcjy at 2017-07-12 23:46:50 #include <iostream> #include <cstring> #include <cstdio> #include <queue> #include <algorithm> using namespace std; char map1[35][35][35]; int vis[35][35][35]; int choose[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}}; int k,n,m; int sx,sy,sz,ex,ey,ez; struct node { int z,x,y,step; }; int check(int z,int x,int y) { if(x<0||y<0||z<0||x>=n||y>=m||z>=k) //if(x<0||y<0||z<0||x>k||y>n||z>m) return 1; if(map1[z][x][y]=='#') return 1; if(vis[z][x][y]==1) return 1; return 0; } int bfs() { node a; a.x=sx,a.y=sy,a.z=sz,a.step=0; queue <node> Q; Q.push(a); vis[sz][sx][sy]=1; node now,next1; next1.step=0; while(!Q.empty()){ now=Q.front(); Q.pop(); if(now.x==ex&&now.y==ey&&now.z==ez){ while(!Q.empty())Q.pop(); return now.step; } for (int i=0;i<6;i++){ next1.z=now.z+choose[i][0]; next1.x=now.x+choose[i][1]; next1.y=now.y+choose[i][2]; if(check(next1.z,next1.x,next1.y)) continue; //if(map1[next1.z][next1.x][next1.y]=='.') //{ vis[next1.z][next1.x][next1.y]=1; next1.step=now.step+1; Q.push(next1); //} } } return 0; } int main() { //freopen ("in.txt" , "r" , stdin); while (scanf("%d%d%d",&k,&n,&m)&&(n+m+k)) { memset(map1,0,sizeof(map1)); memset(vis,0,sizeof(vis)); for(int i=0;i<k;i++) for(int j=0;j<n;j++) scanf("%s",map1[i][j]); for(int i=0;i<k;i++) for(int j=0;j<n;j++) for(int ii=0;ii<m;ii++) { if(map1[i][j][ii]=='S') sz=i,sx=j,sy=ii; if(map1[i][j][ii]=='E') ez=i,ex=j,ey=ii; } int time; time=bfs(); //printf("%d",time); if(time) printf("Escaped in %d minute(s).\n",time); else printf("Trapped!\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator