看的别人的思路写,还WA了n次,我的心是崩溃的
以后三维坐标统一变成x为z轴好了,省夜长梦多。。。
还有最fuck的一点,我吧queue<node>q定义为全局变量,居然显示WA。实在是不解啊
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
const int N = 20;
const int INF = 1000000;
char Map[2][N][N];
bool vis[2][N][N];
int m, n, t, flag;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
struct node
{
int x, y, z;
int step;
};
node s_pos;
bool check(int x, int y, int z)
{
if(x >= 0 && x < 2 && y >= 0 && y < n && z >= 0 && z < m && Map[x][y][z] != '*') return true;
else return false;
}
void bfs()
{
memset(vis, 0, sizeof(vis));
vis[s_pos.x][s_pos.y][s_pos.z] = true;
queue <node> q;
q.push(s_pos);
while(!q.empty())
{
node tmp = q.front();
q.pop();
if(Map[tmp.x][tmp.y][tmp.z] == 'P' && tmp.step <= t)
{
flag = 1;
return;
}
for(int i = 0; i < 4; i ++)
{
node tmp2;
tmp2 = tmp;
tmp2.y += dir[i][0];
tmp2.z += dir[i][1];
tmp2.step += 1;
if(check(tmp2.x, tmp2.y, tmp2.z) && !vis[tmp2.x][tmp2.y][tmp2.z] && tmp2.step <= t)
{
vis[tmp2.x][tmp2.y][tmp2.z] = 1;
if(Map[tmp2.x][tmp2.y][tmp2.z] == '#')
{
if(Map[(tmp2.x + 1) % 2][tmp2.y][tmp2.z] != '*' && !vis[(tmp2.x + 1) % 2][tmp2.y][tmp2.z])
tmp2.x = (tmp2.x + 1) % 2;
}
q.push(tmp2);
}
}
}
}
int main()
{
// freopen("in.txt", "r", stdin);
int C;
scanf("%d", &C);
while(C --)
{
scanf("%d%d%d", &n, &m, &t);
for(int k = 0; k < 2; k ++)
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
{
cin >> Map[k][i][j];
if(Map[k][i][j] == 'S')
{
s_pos.x = k;
s_pos.y = i;
s_pos.z = j;
s_pos.step = 0;
}
}
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
{
if(Map[0][i][j] == '#' && Map[1][i][j] == '*')
Map[0][i][j] = '*';
else if(Map[0][i][j] == '*' && Map[1][i][j] == '#')
Map[1][i][j] = '*';
else if(Map[0][i][j] == '#' && Map[1][i][j] == '#')
Map[0][i][j] = Map[1][i][j] = '*';
}
flag = 0;
bfs();
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}