请帮我看下下面的题我写的代码为什么没有输出,哪里写错了
题目:
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
Input
输入的第一行C表示共有C个测试数据,每个测试数据的前一行有三个整数N,M,T。 N,M迷宫的大小NM(1 <= N,M <=10)。T如上所意。接下去的前NM表示迷宫的第一层的布置情况,后NM表示迷宫第二层的布置情况。
Output
如果骑士们能够在T时刻能找到公主就输出“YES”,否则输出“NO”。
样例输出:
1
5 5 14
S*#*.
.#...
.....
****.
...#.
...P
#...
***..
...*.
*.#..
样例输出:
YES
我的代码:
#include "iostream"
#include "queue"
#include "cstring"
using namespace std;
int c;
int n, m, v;
char map1[15][15];
int abookmap1[15][15];
char map2[15][15];
int abookmap2[15][15];
int next1[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };
struct point {
int x;
int y;
int floor;
int step;
};
int main() {
queue<point>q;
memset(abookmap1, 0, sizeof(abookmap1));
memset(abookmap2, 0, sizeof(abookmap2));
cin >> c;
while (c--) {
cin >> n >> m >> v;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
cin >> map1[i][j];
if (map1[i][j] == 'S')
{
q.push(point{ i,j,1,0 });
map1[i][j] = '*';
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> map2[i][j];
while (!q.empty()) {
point t = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int tx = t.x + next1[i][0];
int ty = t.y + next1[i][1];
if (tx<1 || ty<1 || tx>n || ty>m)continue;
if ((t.floor == 1 && abookmap1[tx][ty] == 1) || (t.floor == 1 && map1[tx][ty] == '*'))continue;
if(t.floor == 2 && abookmap2[tx][ty] == 1 || (t.floor == 2 && map2[tx][ty] == '*'))continue;
if (t.floor == 1) {
if (map1[tx][ty] == '.')
{
q.push(point{ tx,ty,1,t.step + 1 });
abookmap1[tx][ty] = 1;
}
if (map1[tx][ty] == '#') {
q.push(point{ tx,ty,2,t.step + 1 });
abookmap2[tx][ty] = 1;
abookmap1[tx][ty] = 1;
}
if (map1[tx][ty] == 'P')
{
int temp = t.step + 1;
if (temp <= v)
cout << "YES" << endl;
else cout << "NO" << endl;
abookmap1[tx][ty] = 1;
}
}
if (t.floor == 2) {
if (map2[tx][ty] == '.')
{
q.push(point{ tx,ty,2,t.step + 1 });
abookmap2[tx][ty] = 1;
}
if (map2[tx][ty] == '#') {
q.push(point{ tx,ty,1,t.step + 1 });
abookmap2[tx][ty] = 1;
abookmap1[tx][ty] = 1;
if (map2[tx][ty] == 'P')
{
int temp = t.step + 1;
if (temp <= v)
cout << "YES" << endl;
else cout << "NO" << endl;
abookmap2[tx][ty] = 1;
}
}
}
}
}
}
}