poj 2251 Dungeon Master

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; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值