http://162.105.81.212/JudgeOnline/problem?id=2251
开使用深搜超时了, 然后改用广搜.
很快就写完了, 然后提交WA,....
找了半天也没找到错误, 胡乱改了点, 提交, WA...-_-
然后就去做2225那题(都是3维广搜), 一次就AC
回来我发现我的输出竟然是: Escaped in 11 mMinute(s).
暴汗, 我记得当时是复制的Sample Input的, 怎么就把minute就复制成mMinute了, 囧
#include<iostream> #include<queue> using namespace std; struct Point { int x, y, z, step; Point(){} Point(int a, int b, int c) { x = a; y = b; z = c; } }S; int L, R, C; char c[31][31][35]; Point dir[] = { Point(0, 0, -1), Point(-1, 0, 0), Point(0, 0, 1), Point(1, 0, 0), Point(0, -1, 0), Point(0, 1, 0) }; inline bool check(Point p) { if(p.x >= 0 && p.y >= 0 && p.z >= 0 && p.x < L && p.y < R && p.z < C) return 1; else return 0; } int bfs(Point p) { queue<Point> Que; Que.push(p); Point point, tmp; while(!Que.empty()) { point = Que.front(); Que.pop(); for(int i=0; i<6; i++) { tmp.x = point.x + dir[i].x; tmp.y = point.y + dir[i].y; tmp.z = point.z + dir[i].z; tmp.step = point.step + 1; if(check(tmp) && c[tmp.x][tmp.y][tmp.z] == '.') { c[tmp.x][tmp.y][tmp.z] = '#'; Que.push(tmp); } else if(c[tmp.x][tmp.y][tmp.z] == 'E') return tmp.step; } } return -1; } int main() { //freopen("in.txt", "r", stdin); int i, j, k; while(scanf("%d%d%d", &L, &R, &C) && (L||R||C)) { memset(c, -1, sizeof(c)); for(i=0; i<L; i++) { for(j=0; j<R; j++) { scanf("%*c"); for(k=0; k<C; k++) { c[i][j][k] = getchar(); if(c[i][j][k] == 'S') { S.x = i; S.y = j; S.z = k; S.step = 0; } } } scanf("%*c"); } int step = bfs(S); if(step == -1) puts("Trapped!"); else printf("Escaped in %d minute(s)./n", step); } return 0; }