标签:targe output 遇到 计划 nbsp size color front 二层
题目链接:https://vjudge.net/problem/HDU-2102
题目:
1 5 5 14 S*#*. .#... ..... ****. ...#. ..*.P #.*.. ***.. ...*. *.#..Sample Output
YES
思路:bfs,三维坐标
// // Created by hanyu on 2019/7/11. // #include<iostream> #include<queue> #include<cstring> #include<cstdio> using namespace std; int N,M,T; struct node{ int x,y,z; int dept; }; int book[11][11][11]; int dic[4][2]={{0,1},{1,0},{-1,0},{0,-1}}; char str[12][12][12]; bool bfs(int x,int y,int z) { queue<node>qu; node now,next; now.x=x; now.y=y; now.z=z; now.dept=0; book[x][y][z]=1; qu.push(now); while(!qu.empty()) { now=qu.front(); qu.pop(); if(str[now.x][now.y][now.z]==‘P‘) return true; if(now.dept>=T) return false; for(int i=0;i<4;i++) { int a=now.x; int b=now.y+dic[i][0]; int c=now.z+dic[i][1]; if(b<0||c<0||b>=N||c>=M||str[a][b][c]==‘*‘||book[a][b][c]) continue; book[a][b][c]=1; if(str[a][b][c]==‘#‘) { a=!a;//传送到另一层 if(str[a][b][c]==‘*‘||str[a][b][c]==‘#‘||book[a][b][c]==1)//遇到墙撞死,遇到#则无限循环 continue; book[a][b][c]=1; } next.x=a; next.y=b; next.z=c; next.dept=now.dept+1; qu.push(next); } } return false; } int main() { int h; cin>>h; while(h--) { cin>>N>>M>>T; for(int i=0;i<2;i++) { for(int j=0;j<N;j++) { scanf("%s",str[i][j]); } } memset(book,0,sizeof(book)); if(bfs(0,0,0)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
标签:targe output 遇到 计划 nbsp size color front 二层
原文地址:https://www.cnblogs.com/Vampire6/p/11173365.html