poj 2251 Dungeon Master
来源:互联网 发布:加拿大 留学 专业 知乎 编辑:程序博客网 时间:2024/05/17 04:37
题目链接:Dungeon Master
题目大意:给你一个三维的空间,然后给你起点和终点,中间有墙壁不能访问,问是否能从起点访问到终点,如果能,输出最短路径
题目思路:水题,写一个简单的bfs就可以了
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#include <iostream>#include <queue>using namespace std;int k,n,m,sx,sy,sz,ex,ey,ez;char mp[35][35][35];int dir[6][3] = {{1,0,0},{-1,0,0},{0,-1,0},{0,1,0},{0,0,1},{0,0,-1}};bool vis[35][35][35];struct node{ int x,y,z,step;};bool check(int x,int y,int z){ if(x < 0||y < 0||z < 0||x >= k||y >= n||z >= m||vis[x][y][z]||mp[x][y][z] == '#') return true; return false;}int bfs(){ node a,next; queue<node>Q; a.x = sx,a.y = sy,a.z = sz,a.step = 0; vis[sx][sy][sz] = true; Q.push(a); while(!Q.empty()){ a = Q.front(); Q.pop(); if(a.x == ex&&a.y == ey&&a.z == ez) return a.step; for(int i = 0;i < 6;i++){ 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.x,next.y,next.z)) continue; vis[next.x][next.y][next.z] = true; next.step = a.step + 1; Q.push(next); } } return 0;}int main(){ while(~scanf("%d%d%d",&k,&n,&m),n+m+k){ for(int i = 0;i < k;i++){ for(int j = 0;j < n;j++){ scanf("%s",mp[i][j]); for(int r = 0;r < m;r++){ if(mp[i][j][r] == 'S') sx = i,sy = j,sz = r; if(mp[i][j][r] == 'E') ex = i,ey = j,ez = r; } } } memset(vis,false,sizeof(vis)); int ans = bfs(); if(ans != 0) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); } return 0;}
0 0
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- Poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- POJ 2251Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 - Dungeon Master
- POJ 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- poj 2251 Dungeon Master
- python 统计文本文件中单词出现的个数
- iOS中数组字典里面在放数组字典
- 数据结构--二叉树的便遍历
- HDU4920:Matrix multiplication(思维 & bitset)
- iOS GCD之dispatch_semaphore(信号量)
- poj 2251 Dungeon Master
- jsoncpp封装和解析字符串、数字、布尔值和数组
- 注解(Annotation)自定义注解入门
- 写Python爬虫的准备工作
- ASP.NET 判断是否是连续的数字(可重复,但必须是连续的数字)
- android 实现图标 (图片)拖拽移动
- mook 离港篇之 引用 与 const
- 自动无限轮播图,支持多种自定义效果
- 冒泡排序