栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1940 Dungeon Master

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1940 Dungeon Master

#include <cstdio>#include<iostream>#include <queue>using namespace std;const int N = 85;char map[N][N][N];   int l,r,c;struct Node{    int x,y,z;    int step;};int dir[8][4]={    {0,0,1},    {0,0,-1},    {0,1,0},    {0,-1,0},    {1,0,0},    {-1,0,0}};int Bfs(Node st,Node en){    queue<Node> q;    Node tmd,tmp;    q.push(st);    while(!q.empty())    {        tmd=q.front();q.pop();if(tmd.x==en.x && tmd.y==en.y && tmd.z==en.z) return tmd.step;        for(int i=0;i<6;i++)        { tmp.x=tmd.x+dir[i][0]; tmp.y=tmd.y+dir[i][1]; tmp.z=tmd.z+dir[i][2]; tmp.step=tmd.step+1; if(map[tmp.x][tmp.y][tmp.z]!='#'&&tmp.x>=0 &&tmp.y>=0 && tmp.z>=0 &&tmp.x<l&&tmp.y<r&&tmp.z<c) {      q.push(tmp);     map[tmp.x][tmp.y][tmp.z]='#'; }        }    }    return -1;}int main(){    while(~scanf("%d%d%d",&l,&r,&c))    {        if(l==0 && r==0 &&c==0) break;        getchar();        Node st,en;        for(int i=0;i<l;i++)        { for(int j=0;j<r;j++) {     for(int k=0;k<c;k++)     {         scanf("%c",&map[i][j][k]);         if(map[i][j][k]=='S')         {  st.x=i; st.y=j; st.z=k;st.step=0;         }         if(map[i][j][k]=='E')         {  en.x=i,en.y=j,en.z=k;         }     }     getchar(); } if(i!=l-1)     getchar();        }        int ans = Bfs(st,en);        if(ans == -1){ printf("Trapped!n");        }else        { printf("Escaped in %d minute(s).n",ans);        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375605.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号