国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望城县| 蚌埠市| 寻乌县| 华坪县| 贵定县| 金山区| 宁南县| 库伦旗| 绥中县| 衡东县| 山丹县| 湄潭县| 石家庄市| 黑山县| 襄垣县| 平利县| 荔浦县| 尚志市| 马龙县| 巨野县| 海原县| 勃利县| 宜章县| 分宜县| 潢川县| 鹿邑县| 呼玛县| 渝北区| 南昌市| 黑龙江省| 上林县| 屏山县| 福泉市| 南陵县| 织金县| 澄城县| 华亭县| 铜梁县| 安达市| 新干县| 铜梁县|