本来以为进阶搜索会有难一点的剪枝,没想到这个这么水。。
https://vjudge.net/problem/HDU-2102
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n, m, t;
char a[3][15][15];
bool vis[3][15][15];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
struct node
{
int x, y, z, t;
};
bool bfs(int z, int x, int y)
{
queue<node> q;
node h, next;
h.x = x, h.y = y, h.z = z;
h.t = 0;
q.push(h);
vis[z][x][y] = 1;
//int miny = inf;
while(! q.empty())
{
h = q.front();
q.pop();
if(h.t > t) return 0;
for(int i = 0; i < 4; i ++)
{
int u = h.x + dir[i][0];
int v = h.y + dir[i][1];
int p = h.z;
if(u >= 1 && u <= n && v >= 1 && v <= m && ! vis[p][u][v] && a[p][u][v] != '*')
{
if(a[p][u][v] == 'P')
{
return (h.t + 1 <= t);
}
else if(a[p][u][v] == '#')
{
p += 1;
if(p > 2) p -= 2;
if(a[p][u][v] == '*' || a[p][u][v] == '#')
{
vis[p][u][v] = 1;
continue;
}
else if(a[p][u][v] == 'P') return (h.t + 1 <= t);
else
{
vis[p][u][v] = 1;
next.z = p, next.x = u, next.y = v;
next.t = h.t + 1;
q.push(next);
//miny = min(miny, next.t);
}
}
else
{
vis[p][u][v] = 1;
next.z = p, next.x = u, next.y = v;
next.t = h.t + 1;
q.push(next);
//miny = min(next.t, miny);
}
}
}
//if(miny > t) return 0;
}
return 0;
}
int main()
{
int T;
scanf("%d", &T);
while(T --)
{
scanf("%d%d%d" ,&n, &m, &t);
for(int k = 1; k <= 2; k ++)
for(int i = 1; i <= n; i ++)
//for(int j = 1; j <= m; j ++)
scanf("%s", a[k][i] + 1);
memset(vis, 0, sizeof(vis));
if(bfs(1, 1, 1)) printf("YES\n");
else printf("NO\n");
}
return 0;
}