WA了两天……debug出来的时候开心到炸……怎么看怎么没毛病……
#include<iostream> #include<string> #include<string.h> #include<stdio.h> #include<queue> using namespace std; char mize[2][15][15]; int dis[2][15][15]; int T,t, m, n; int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }; bool bfs() { memset(dis, -1, sizeof(dis)); int p = 0; queue<int>q; q.push(p); dis[0][0][0] = 0; while (!q.empty()) { p = q.front(); q.pop(); int c = p / (m*n); int x = (p - c*m*n) / m; int y = (p - c*m*n) % m; if (mize[c][x][y] == 'P') return dis[c][x][y] <= t; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || ny < 0 || nx >= n || ny >= m || mize[c][nx][ny] == '*' || dis[c][nx][ny] != -1) continue; if (mize[c][nx][ny] == '#'&&mize[c ^ 1][nx][ny] == '#') continue; if(mize[c][nx][ny] == '#'&&mize[c ^ 1][nx][ny] == '*') continue; dis[c][nx][ny] = dis[c][x][y] + 1; if (mize[c][nx][ny] == '#') { dis[c ^ 1][nx][ny] = dis[c][nx][ny]; q.push((1-c)*n*m + nx*m + ny); } else q.push(c*n*m + nx*m + ny); /*错误示范: dis[c ][nx][ny] = dis[c][x][y]+1; if (mize[c][nx][ny] == '#') { dis[c ^ 1][nx][ny] = dis[c][nx][ny]; c^=1; } q.push(c*n*m + nx*m + ny); */ } } return false; } int main() { scanf("%d", &T); getchar(); while (T--) { scanf("%d %d %d", &n, &m, &t); getchar(); for (int k = 0; k < 2; k++) { for (int i = 0; i < n; i++) scanf("%s", mize[k][i]); if (k == 0) getchar(); } if (bfs()) puts("YES"); else puts("NO"); } return 0; }