标签:
1 5 5 14 S*#*. .#... ..... ****. ...#. ..*.P #.*.. ***.. ...*. *.#..
YES
//‘*‘表示石头
// ‘#‘表示经过了就必须要穿越到另外的
//‘.‘可以走的路,但要花时间
#include <cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct help
{
int x,y,z;
int time;
};
char map[15][15][15];
bool vis[15][15][15];
int ex,ey,ez;
int sx,sy,sz;
int dx[]={0,0,-1,1,0,0};
int dy[]={1,-1,0,0,0,0};
int dz[]={0,0,0,0,-1,1};
int n,m,limit;
bool judge(int x,int y,int z)
{
if(vis[z][x][y] || x>n || x<1 || y>m || y<1 || map[z][x][y]=='*')
return 0;
return 1;
}
int BFS()
{
memset(vis,0,sizeof(vis));
queue<help>q;
help pos,next;
pos.x=sx;
pos.y=sy;
pos.z=sz;
pos.time=0;
vis[0][1][1]==1;
q.push(pos);
while(!q.empty())
{
pos=q.front();
q.pop();
for(int i=0;i<4;++i)
{
next.x=pos.x+dx[i];
next.y=pos.y+dy[i];
next.z=pos.z;
next.time=pos.time+1;
if(!vis[next.z][next.x][next.y]&&map[next.z][next.x][next.y]=='#')
{
if(map[!next.z][next.x][next.y]=='#'||map[next.z][next.x][next.y]=='*')
{
vis[next.z][next.x][next.y]=1;
continue;
}
next.z=!next.z;
}
if(judge(next.x,next.y,next.z))
{
if(next.x==ex&&next.y==ey&&next.z==ez)
{
return next.time;
}
vis[next.z][next.x][next.y]=1;
q.push(next);
}
}
}
return -1;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&limit);
getchar();
for(int i=0;i<=1;++i)
{
for(int j=1;j<=n;++j)
{
for(int k=1;k<=m;++k)
{
scanf("%c",map[i][j]+k);
if(map[i][j][k]=='P')
ez=i,ex=j,ey=k;
else if(map[i][j][k]=='S')
sz=i,sx=j,sy=k;
}
getchar();
}
if(!i)
getchar();
}
int min_time=BFS();
if(min_time==-1||(min_time>limit))
printf("NO\n");
else printf("YES\n");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/yuzhiwei1995/article/details/47378117