题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2102
简单搜索,注意上下层对应位置都是传送口的情况,在T时刻之前到达就行。
简单搜索,注意上下层对应位置都是传送口的情况,在T时刻之前到达就行。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 15
#define M 10000
#define CLR(arr,v) memset(arr,v,sizeof(arr))
struct point
{
int x,y,z,t;
}mid,que[10005],p;
int n,m,t,head,total,dis[2][15][15];
int d[4][2] = {-1,0,1,0,0,-1,0,1};
char map[2][15][15];
void init()
{
head = total = 0;
CLR(que,0);
for(int i = 0;i < 2;++i)
for(int j = 0;j < 15;++j)
for(int k = 0;k < 15;++k)
{
dis[i][j][k] = INT_MAX;
map[i][j][k] = '0';
}
}
int bfs()
{
dis[0][1][1] = 0;
mid.x = 1; mid.y = 1;
mid.z = 0; mid.t = 0;
que[total++] = mid;
while(head < total)
{
p = que[head++];
if(head >= M) head %= M;
int x = p.x,y = p.y,z = p.z,v = p.t;
if(map[z][x][y] == 'P') return v;
if(map[z][x][y] == 'S' || map[z][x][y] == '.')
{
for(int i = 0;i < 4;++i)
{
if((map[z][ x+d[i][0] ][ y+d[i][1] ] == '.' || map[z][ x+d[i][0] ][ y+d[i][1] ] == '#' || map[z][ x+d[i][0] ][ y+d[i][1] ] == 'P') && v + 1 < dis[z][ x+d[i][0] ][ y+d[i][1] ])
{
mid.x = x + d[i][0];
mid.y = y + d[i][1];
mid.z = z;
mid.t = v + 1;
dis[z][ x+d[i][0] ][ y+d[i][1] ] = v + 1;
que[total++] = mid;
if(total > M) total %= M;
}
}
}
if(map[z][x][y] == '#')
{
z = z?0:1;
if(map[z][x][y] != '*' && map[z][x][y] != '#' && v < dis[z][x][y])
{
mid.x = x; mid.y = y;
mid.t = v; mid.z = z;
dis[z][x][y] = v ;
que[total++] = mid;
if(total >= M) total %= M;
}
}
}
return INT_MAX;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
init();
scanf("%d%d%d",&m,&n,&t);
for(int i = 1;i <= m;++i)
scanf("%s",&map[0][i][0]+1);
for(int i = 1;i <= m;++i)
scanf("%s",&map[1][i][0]+1);
printf(t >= bfs()?"YES\n":"NO\n");
}
return 0;
}