UVA 532--Dungeon Master
来源:互联网 发布:ie加载项里面没有java 编辑:程序博客网 时间:2024/06/18 13:01
题意:给你一个空间图形,空间图形由 ‘#‘ ‘S‘ ’E‘ ‘.’ 等元素组成求能否从S到达E。能到达输出最小步数。
分析:bfs,由于空间图形较小直接bfs模拟搜索即可。
#include<bits/stdc++.h>using namespace std;const int Max=50;int n,m,r;char mp[Max][Max][Max];int flag[Max][Max][Max];int dx[]={0,-1,0,1,0,0};int dy[]={0,0,1,0,-1,0};int dz[]={-1,0,0,0,0,1};struct node{ int x; int y; int z;};node t,t1;queue<node>check;void bfs(){ while(check.empty()==0) { t=check.front(); check.pop(); for(int i=0;i<6;i++) { int xx=t.x+dz[i]; int yy=t.y+dx[i]; int zz=t.z+dy[i]; if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&zz>=1&&zz<=r&&mp[xx][yy][zz]!='#'&&flag[xx][yy][zz]==-1) { t1.x=xx; t1.y=yy; t1.z=zz; check.push(t1); flag[xx][yy][zz]=flag[t.x][t.y][t.z]+1; } } }}int main(){ while(cin>>n>>m>>r) { if(n==0&&m==0&&r==0)break; memset(flag,-1,sizeof(flag)); while(check.empty()==0) { check.pop(); } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { for(int k=1;k<=r;k++) { cin>>mp[i][j][k]; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { for(int k=1;k<=r;k++) { if(mp[i][j][k]=='S') { t.x=i; t.y=j; t.z=k; flag[i][j][k]=0; check.push(t); bfs(); } } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { for(int k=1;k<=r;k++) { if(mp[i][j][k]=='E'&&flag[i][j][k]==-1) { cout<<"Trapped!"<<endl; } else if(mp[i][j][k]=='E'&&flag[i][j][k]!=-1) { cout<<"Escaped in "<<flag[i][j][k]<<" minute(s)."<<endl; } } } } } return 0;}
阅读全文
0 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
- vs2017上配置HALCON 12
- Android自定义属性,format详解
- WebStorm与Git使用指南
- Markdown系列(1)- 语法手册
- Kafka学习之一 :安装启动
- UVA 532--Dungeon Master
- 从A到B再到C
- 手动释放(dispose)对象空间和跟踪引用计数
- 爬虫1.1爬取斗图啦图片(关于open函数和urlretrieve函数)
- Python用户推荐系统曼哈顿算法实现
- 剑指offer——面试题42:翻转单词序列
- 如何把自媒体平台文章同步到WordPress等网站
- 在SpringBoot项目中添加logback的MDC
- Android的manifest中Application属性supportsRtl的作用