poj-2251 广搜
来源:互联网 发布:拓扑图制作软件 编辑:程序博客网 时间:2024/04/30 16:33
http://poj.org/problem?id=2251
#include<stdio.h> #include<iostream> #include<math.h> #include<stdlib.h> #include<ctype.h> #include<algorithm> #include<vector> #include<string.h> #include<queue> #include<stack> #include<set> #include<sstream> #include<time.h> #include<utility> #include<malloc.h> #include<stdexcept> #include<iomanip> #include<iterator> using namespace std;char map[40][40][40];int vis[40][40][40];int L, R, C;struct node{int z, x, y;int c;};int dir[6][3] = { { 1, 0, 0 }, { -1, 0, 0 }, { 0, -1, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, { 0, 0, 1 } };int BFS(int si, int sj, int sk){memset(vis, 0, sizeof(vis));queue<node> q;node cur, next;cur.z = si, cur.x = sj, cur.y = sk, cur.c = 0;vis[si][sj][sk] = 1;q.push(cur);while (!q.empty()){cur = q.front();q.pop();for (int i = 0; i < 6; i++){next.z = cur.z + dir[i][0];next.x = cur.x + dir[i][1];next.y = cur.y + dir[i][2];next.c = cur.c + 1;if (next.z<1 || next.z>L || next.x<1 || next.x>R || next.y<1 || next.y>C || map[next.z][next.x][next.y] == '#')continue;if (map[next.z][next.x][next.y] == 'E')return next.c;if (!vis[next.z][next.x][next.y]){vis[next.z][next.x][next.y] = 1;q.push(next);}}}return 0;}int main(){int si, sj, sk;while (cin >> L >> R >> C){if (L == 0 && R == 0 && C == 0)break;for (int i = 1; i <= L; i++)for (int j = 1; j <= R; j++)for (int k = 1; k <= C; k++){cin >> map[i][j][k];if (map[i][j][k] == 'S'){si = i; sj = j; sk = k;}}int ans = BFS(si, sj, sk);if (ans == 0)printf("Trapped!\n");elseprintf("Escaped in %d minute(s).\n", ans);}return 0;}
0 0
- poj-2251 广搜
- POJ 2251 三维广搜。
- POJ 2251 Dungeon Master (广搜)
- POJ:2251 Dungeon Master(广搜)
- POJ 2251 Dungeon Master(广搜)
- 广搜 poj 3126
- POJ 3126 广搜
- POJ 2049 广搜
- 广搜poj.3009
- POJ 2243 广搜
- poj 3414 广搜
- poj 3278 广搜
- POJ 3087 广搜
- POJ 1915 双向广搜
- 广搜1 poj 2243
- POJ 3126 素数+广搜
- POJ 1426 广搜BFS
- POJ 1915 双向广搜
- php连接Mysql的增删改查操作
- web开发---给<td>添加超链接
- 寒假计划
- 圃侗靠鸦醇罩该释讯猿赣诽凡涂母
- MySQL 数据库概述及其入门语句
- poj-2251 广搜
- Python在Windows上的安装
- 噬瞥独挝姆纳杜阜涤翘阜岩源哑档
- 辛沧闭景婆该胶扔技蛊壬被幽谔乘
- 局豆构巢芬吞疚厮采柑沮偌匾垢帕
- 氯沸研猛适煞阶趟腿胶稼概翟怂热
- 磕幽仪父侣嚎乔剂刈习且扔妹图疵
- 2015年IT业薪酬展望:开发、技术支持、项目经理……
- d2 关键字 标识符定义规范 常量变量 作用域 printf scanf