Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=940
Analysis: three-dimensional is actually six directions to search, clear and careful thinking, and soon AC.
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 100010using namespacestd;structnode{intX,y,z,step;};structmove{intL,r,c;} mo[6]={ {0,0,1},{0,0,-1},{0,1,0}, {0,-1,0},{1,0,0},{-1,0,0}};Chars[ *][ *][ *];intvis[ *][ *][ *];intL,r,c;node Make_node (intAintBintCintx) {Node temp; Temp.x=a,temp.y=b; Temp.z=c;temp.step=x; returntemp;} Queue<node>que;BOOLJudgeintAintBintc) { returna>=0&&a<l&&b>=0&&b<r&&c>=0&&c<c&&s[a][b][c]!='#';}intBFsintXintYintz) {memset (Vis,0,sizeof(VIS)); while(!que.empty ()) Que.pop (); Que.push (Make_node (x, Y, Z,0)); VIS[X][Y][Z]=1; while(!Que.empty ()) {Node now=Que.front (); Que.pop (); for(intI=0;i<6; i++) { inta=now.x+mo[i].l,b=now.y+mo[i].r,c=now.z+mo[i].c,x=Now.step; if(!vis[a][b][c]&&judge (A,b,c)) {Que.push (Make_node (a,b,c,x+1)); VIS[A][B][C]=1; if(s[a][b][c]=='E') { returnx+1; } } } } return-1;}intMain () {intans,x,y,z; while(SCANF ("%d%d%d", &l,&r,&c) &&L) { for(intI=0; i<l;i++) for(intj=0; j<r;j++) {scanf ("%s", S[i][j]); for(intk=0; k<c;k++) { if(s[i][j][k]=='S') {x=i;y=j;z=K; } } } intres=BFS (x, y, z); if(res!=-1) printf ("escaped in%d minute (s). \ n", RES); ElsePuts"trapped!"); }}View Code
zoj1940 (three-dimensional wide search)