ZOJ 1940 Dungeon Master

三维迷宫..现在这种题真的是根切菜一样.....

 

#include<cstdio> #include<cstring> #include<cstdlib> #include<queue> char mat[32][32][32]; int dir[6][3] = {1,0,0,-1,0,0, 0,1,0,0,-1,0, 0,0,1,0,0,-1}; int flag[32][32][32]; struct point { int x,y,z; int ceng; }t,e,start,end; int main(void) { int n,m,l; int i,j,k; std::queue<struct point> q; while( scanf("%d%d%d",&l,&n,&m) != EOF) { if( l==0&&n==0&&m==0) break; getchar(); for( i = 0; i <=l+1; i++) for( j = 0; j <= n+1; j++ ) for( k = 0; k <=m+1; k++) mat[j][k][i] = '#'; for( i = 1; i <= l; i++ ) { for( j= 1; j <= n; j++ ) { for( k = 1; k <= m; k++) { scanf("%c",&mat[j][k][i]); if( mat[j][k][i] == 'S') start.x=j,start.y=k,start.z=i; if( mat[j][k][i] == 'E') end.x=j,end.y=k,end.z=i; } getchar(); } getchar(); } memset(flag,0,sizeof(flag)); start.ceng=0; flag[start.x][start.y][start.z] = 1; q.push(start); while( !q.empty() ) { e = q.front();q.pop(); if( e.x==end.x && e.y == end.y&& e.z==end.z) break; for( i = 0; i <6; i++) { t = e; t.x += dir[i][0]; t.y += dir[i][1]; t.z += dir[i][2]; t.ceng++; if( !flag[t.x][t.y][t.z] && mat[t.x][t.y][t.z] != '#') { flag[t.x][t.y][t.z] = 1; q.push(t); } } } while( !q.empty() ) q.pop(); if( e.x==end.x && e.y == end.y&& e.z==end.z) printf("Escaped in %d minute(s)./n",e.ceng); else printf("Trapped!/n"); } return 0; }

你可能感兴趣的:(c,struct)