题目:http://poj.org/problem?id=2251

简单三维 bfs不解释, 1A,     上代码

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; int a,b,c;
int vis[][][],G[][][];
int dx[]={,,,,-,};
int dy[]={,,,-,,};
int dz[]={,-,,,,};
struct node
{
int l,r,c,step;
}e,s,pos,next;
int bfs(int l,int r,int c)
{
int i;
queue<node>q;
next.l=l; next.r=r; next.c=c; next.step=;
vis[l][r][c]=;
q.push(next);
while(!q.empty())
{
pos=q.front();
q.pop();
for(i=; i<; i++)
{
next.l=pos.l+dx[i]; next.r=pos.r+dy[i];
next.c=pos.c+dz[i]; next.step=pos.step+;
if(!vis[next.l][next.r][next.c]&&G[next.l][next.r][next.c])
{
vis[next.l][next.r][next.c]=;
q.push(next);
}
if(next.l==s.l&&next.r==s.r&&next.c==s.c)
return next.step;
}
}
return -;
}
int main()
{
int i,j,k,x;
char ch;
while(cin>>a>>b>>c&&(a!=||b!=||c!=))
{
memset(G,,sizeof(G));
memset(vis,,sizeof(vis));
for(i=; i<=a; i++)
for(j=; j<=b; j++)
for(k=; k<=c; k++)
{
cin>>ch;
if(ch=='.')
G[i][j][k]=;
if(ch=='E')
{
e.l=i; e.r=j; e.c=k;
G[i][j][k]=;
}
if(ch=='S')
{
s.l=i; s.r=j; s.c=k;
G[i][j][k]=;
}
}
x=bfs(e.l,e.r,e.c);
if(x==-)
cout<<"Trapped!"<<endl;
else
printf("Escaped in %d minute(s).\n",x);
}
return ;
}

最新文章

  1. 安装cocoapods
  2. TODO:Golang Linux进程退出说明
  3. [python]初试页面抓取——抓取沪深股市交易龙虎榜数据
  4. tensorflow学习笔记五:mnist实例--卷积神经网络(CNN)
  5. activiti 里面各个方法理解
  6. 使用OCR来帮助LR实现认证码识别
  7. linq 多表分组查询统计
  8. 怎样创建FTP服务器
  9. 关于Control flow
  10. erlang 基础知识
  11. Linux学习之lsof命令
  12. SQL中的Update、delete与inner join 联合使用
  13. Swift的属性,方法,下标脚本以及继承
  14. Kettle 5.0源码编译
  15. JDK6和JDK7中String的substring()方法及其差异
  16. Spring中对象和属性的注入方式
  17. 我的Lambda的学习笔记
  18. MAC下 mySQL及workbench安装
  19. Tomcat 配置详解/优化方案(转)
  20. tf 版本更新 记录

热门文章

  1. 解决 Chrome 浏览器自动调整小于11px字体的问题
  2. Redis的PHP操作手册
  3. Java 类和对象
  4. web sevice 生成代理类及使用
  5. SharpDeveloeper开发ASP.NET MVC汗流浃背
  6. Indri中的动态文档索引技术
  7. 演示demo开发问题及解决方案集锦
  8. 信息化的“五观”与“N为”
  9. embed标签遮住div层
  10. 认识OD的两种断点