UVA 532 - Dungeon Master
来源:互联网 发布:python 元组转list 编辑:程序博客网 时间:2024/05/21 07:00
/* 简单的六方向bfs
*/
#include<cstdio>
#include<cstring>#include<queue>
using namespace std;
int l,r,c;
int ex,ey,ez,max1,count,ok;
char map[110][110][110];
int vis[110][110][110];
int d[4][6]= {{0,0,0,0,1,-1},{0,0,1,-1,0,0},{1,-1,0,0,0,0}};
struct node
{
int x,y,z;
int d;
};
int bfs(int x,int y,int z)
{
queue<node> Q;
node t;
t.x=x;
t.y=y;
t.z=z;
t.d=1;
Q.push(t);
while(!Q.empty())
{
node p;
p = Q.front();
Q.pop();
for(int i = 0; i < 6; i++)
{
node q;
q.x = p.x+d[0][i];
q.y = p.y+d[1][i];
q.z = p.z+d[2][i];
if(q.x>=0&&q.y>=0&&q.z>=0&&q.x<=l&&q.y<=r&&q.z<=c)
{
if(map[q.x][q.y][q.z]=='.')
{
map[q.x][q.y][q.z]='#';
q.d=p.d+1;
Q.push(q);
}
else if(map[q.x][q.y][q.z]=='E')
{
ok=1;
if(p.d<max1) max1=p.d;
return 0;
}
}
}
}
return 0;
}
int main()
{
while(scanf("%d %d %d",&l,&r,&c)==3)
{
if(!l&&!c&&!r) break;
getchar();
int x,y,z,flag=0;
for(int i = 0; i < l; i++)
{
for(int j = 0; j < r; j++)
{
gets(map[i][j]);
if(!flag)
for(int k = 0; k < c; k++)
if(map[i][j][k]=='S')
{
x=i;
y=j;
z=k;
flag=1;
break;
}
}
getchar();
}
max1=1<<30;
count=ok=0;
bfs(x,y,z);
if(ok)
printf("Escaped in %d minute(s).\n",max1);
else
printf("Trapped!\n");
memset(vis,0,sizeof(vis));
}
return 0;
}
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva-532 - Dungeon Master
- UVa 532 - Dungeon Master
- UVa 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVa 532Dungeon Master
- uva 532 - Dungeon Master
- UVA 532 Dungeon Master
- uva 532 - Dungeon Master
- uva 532 Dungeon Master
- UVa 532 - Dungeon Master
- UVA 532 Dungeon Master
- UVA 532 - Dungeon Master
- UVA 11234 - Expressions
- jmeter源代码编译+导入到myeclipse
- 线程高级应用-心得4-java5线程并发库介绍,及新技术案例分析
- UVA 548 - Tree
- UVA 10562 - Undraw the Trees
- UVA 532 - Dungeon Master
- UVA 705 - Slash Maze
- shell内建命令和外部命令
- 把slideDown还给IE7—解决IE中slideDown动画出错问题
- Divide and Conquer Transactional Replication using Tracer Tokens
- IoSetCompletionRoutine
- mysql 对varchar型数字排序
- 线程高级应用-心得5-java5线程并发库中Lock和Condition实现线程同步通讯
- cocos2d-x 菜鸟进阶篇(二) 重力感应