标签:turn node body quick app == after find lock
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 62948 | Accepted: 23020 |
Description
Input
Output
Escaped in x minute(s).
Trapped!
Sample Input
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Sample Output
Escaped in 11 minute(s). Trapped!
代码一(STL queue)
#include<cstdio> #include<queue> #include<cstring> using namespace std; struct node { int x, y, z; int step; }S, Node; const int maxn = 35; int X[6] = {1,-1,0,0,0,0}; int Y[6] = {0,0,1,-1,0,0}; int Z[6] = {0,0,0,0,1,-1}; int n, r, c; int ans; bool inq[maxn][maxn][maxn]; char maze[maxn][maxn][maxn]; bool judge(int z, int y, int x) { if(z < 0 || z >= n || y < 0 || y >= r || x < 0 || x >= c || inq[z][y][x] == true|| maze[z][y][x] == ‘#‘) return false; return true; } bool BFS() { queue<node>q; q.push(S); while(!q.empty()) { node top = q.front(); q.pop(); if(maze[top.z][top.y][top.x] == ‘E‘) { if(top.step == 0) return false; else { ans = top.step; return true; } } int ii; for(ii = 0; ii < 6; ii++) { int newX = top.x + X[ii]; int newY = top.y + Y[ii]; int newZ = top.z + Z[ii]; if(judge(newZ, newY, newX)) { Node.x = newX; Node.y = newY; Node.z = newZ; Node.step = top.step+1; q.push(Node); inq[newZ][newY][newX] = true; } } } return false; } int main() { while(scanf("%d%d%d", &n, &r, &c) && n && r && c) { memset(inq, false, sizeof(inq)); int i, j, k; for(i = 0; i < n; i++) { for(j = 0; j < r; j++) { scanf("%s", maze[i][j]); for(k = 0; k < c; k++) { if(maze[i][j][k] == ‘S‘) { S.x = k; S.y = j; S.z = i; } } } } bool p = BFS(); if(!p) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n", ans); } return 0; }
标签:turn node body quick app == after find lock
原文地址:https://www.cnblogs.com/DreamInPal/p/11406428.html