国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

POJ2251 Dungeon Master 【BFS】

2019-11-08 19:34:38
字體:
來源:轉載
供稿:網友

題目鏈接:http://poj.org/PRoblem?id=2251 題意:給你一個三維迷宮,S是起點,E是終點,#不可走 解析:直接開個三維數組,BFS就好

#include <algorithm>#include <cstring>#include <cstdio>#include <queue>using namespace std;const int inf = 0x7fffffff;int L,R,C;int vis[50][50][50];char mapple[50][50][50];int ans;int dx[] = {0,1,-1,0,0,0};int dy[] = {1,0,0,-1,0,0};int dz[] = {0,0,0,0,1,-1};int sx,sy,sz;struct node{ int x,y,z; int step; node() {} node(int _x,int _y,int _z,int _step) { x = _x; y = _y; z = _z; step = _step; }};int bfs(){ ans = inf; memset(vis,0,sizeof(vis)); queue<node> q; q.push(node(sx,sy,sz,0)); vis[sx][sy][sz] = 1; while(!q.empty()) { node now = q.front(); q.pop(); if(mapple[now.x][now.y][now.z]=='E') return now.step; for(int i=0;i<6;i++) { int tx = now.x+dx[i]; int ty = now.y+dy[i]; int tz = now.z+dz[i]; if(tx<0||tx>=L || ty<0||ty>=R || tz<0 || tz>=C) continue; if(mapple[tx][ty][tz]=='#' || vis[tx][ty][tz]) continue; vis[tx][ty][tz] = 1; q.push(node(tx,ty,tz,now.step+1)); } } return inf;}int main(void){ while(~scanf("%d %d %d",&L,&R,&C)) { if(L==0&&R==0&&C==0) break; for(int i=0;i<L;i++) { for(int j=0;j<R;j++) { scanf("%s",mapple[i][j]); for(int k=0;k<C;k++) { if(mapple[i][j][k]=='S') { sx = i; sy = j; sz = k; } } } } ans = bfs(); if(ans==inf) puts("Trapped!"); else printf("Escaped in %d minute(s)./n",ans); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 庆元县| 宣汉县| 凤阳县| 许昌市| 安阳市| 阳泉市| 广昌县| 左云县| 浪卡子县| 江孜县| 承德县| 威宁| 巴彦淖尔市| 亚东县| 博罗县| 梧州市| 绥中县| 井陉县| 黔南| 黄梅县| 舒城县| 平昌县| 惠来县| 宜川县| 额敏县| 鄂州市| 富阳市| 双桥区| 互助| 丰宁| 北宁市| 拜泉县| 苏尼特右旗| 紫金县| 上林县| 泸州市| 平昌县| 塔河县| 嘉祥县| 威信县| 静宁县|