POJ2251 BFS
来源:互联网 发布:百川环评工程师软件 编辑:程序博客网 时间:2024/05/19 12:37
题目
上代码
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;struct node{ int x, y, z, step;};int ex, ey, ez;int L, R, C; //六个方向int dir[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};int visit[35][35][35];char M[35][35][35];node s;int check(node a){ if(a.x < 0 || a.x >= L || a.y < 0 || a.y >= R || a.z < 0 || a.z >= C) return 1; else if(visit[a.x][a.y][a.z]) return 1; else if(M[a.x][a.y][a.z] == '#') return 1; return 0;}int dfs(){ queue<node> q; q.push(s); node a; while(!q.empty()) { a = q.front(); q.pop(); visit[a.x][a.y][a.z] = 1; if(a.x == ex && a.y == ey && a.z == ez) return a.step; for(int i = 0; i < 6; i++) { node next; next = a; next.x = a.x+dir[i][0]; next.y = a.y+dir[i][1]; next.z = a.z+dir[i][2]; if(check(next)) continue; next.step = a.step+1; visit[next.x][next.y][next.z] = 1; q.push(next); } } return 0;}int main(){ //freopen("in.txt", "r", stdin); while(cin >> L >> R >> C && L) { memset(visit, 0, sizeof(visit)); for(int i = 0; i < L; i++) for(int j = 0; j < R; j++) for(int k = 0; k < C; k++) { cin >> M[i][j][k]; if(M[i][j][k] == 'S') { s.x = i; s.y = j; s.z = k;}//起点 if(M[i][j][k] == 'E') { ex = i; ey = j; ez = k;}//终点 } int ans = dfs(); if(ans) printf("Escaped in %d minute(s).\n", ans); else printf("Trapped!\n"); } return 0;}
阅读全文
0 0
- poj2251 bfs
- poj2251 bfs
- POJ2251 BFS
- POJ2251 BFS
- poj2251 Dungeon Master (BFS)
- POJ2251 BFS基础题
- Dungeon Master(poj2251,bfs)
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master bfs
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master(BFS)
- POJ2251 Dungeon Master BFS
- [bfs]poj2251 Dungeon Master
- poj2251 dungeon master【BFS】~
- POJ2251 Dungeon Master(bfs)
- POJ2251 三维的bfs
- poj2251 三维bfs
- POJ2251 Dungeon Master(BFS)
- nodejs的helloworld
- iOS_LocalPush_本地推送
- GG and MM
- RecyclerView点击事件
- POJ-3984迷宫问题 (BFS,水题)
- POJ2251 BFS
- 刷题打卡2 UVa1590,UVa508, UVa509
- 二叉排序树--cf675d Tree construction
- P3741 honoka的键盘
- Python字典对象实现原理
- 8.10关于二维数组
- 8.10
- 操作数据库(增删改查)
- Python 身份运算符