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 |
怎么一直wa啊,求指点怎么一直wa啊#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 x,y,z,step; }; int check(int x,int y,int z) { if(x<0||y<0||z<0||x>k||y>n||z>m) return 1; if(map1[x][y][z]=='#') return 1; if(vis[x][y][z]==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[sx][sy][sz]=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.x=now.x+choose[i][0]; next1.y=now.y+choose[i][1]; next1.z=now.z+choose[i][2]; if(check(next1.x,next1.y,next1.z)) continue; if(map1[next1.x][next1.y][next1.z]=='.') {vis[next1.x][next1.y][next1.z]=1; next1.step=now.step+1; Q.push(next1); } } } return 0; } int main() { 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') sx=i,sy=j,sz=ii; if(map1[i][j][ii]=='E') ex=i,ey=j,ez=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