蒟蒻76分求调,2,3,4,6WA
看了一下第二个测试点,发现走不到终点,但是我又找不到错误点,求大佬看看
#include <bits/stdc++.h>
using namespace std;
#define MAX_SIZE 305
// 传送装置的坐标
class Transmit {
public:
int startX, startY, endX, endY;
};
Transmit tr[30]; // 对应传送装置字母A-Z
char diTu[MAX_SIZE][MAX_SIZE];
bool vis[MAX_SIZE][MAX_SIZE];
int n, m;
int xx, yy; // 起始位置
int endXX, endYY; // 结束位置
int dx[] = {0, 0, 1, 0, -1};
int dy[] = {0, 1, 0, -1, 0};
queue<int> s[3]; // s[0]是x坐标,s[1]是y坐标,s[3]是时间
void bfs() {
s[0].push(xx);
s[1].push(yy);
s[2].push(0);
while (!s[0].empty()) {
int curx = s[0].front();
int cury = s[1].front();
int time = s[2].front();
s[0].pop(), s[1].pop(), s[2].pop();
if (diTu[curx][cury] == '=') { // 到出口
cout << time << endl;
return;
}
if (diTu[curx][cury] >= 'A' && diTu[curx][cury] <= 'Z') { // 传送门
int ind = diTu[curx][cury] - 'A';
if (curx == tr[ind].startX) {
curx = tr[ind].endX;
cury = tr[ind].endY;
} else {
curx = tr[ind].startX;
cury = tr[ind].startY;
}
}
for (int i = 1; i <= 4; i++) {
int nx = curx + dx[i];
int ny = cury + dy[i];
// 越界 || 不可走 || 走过了
if (nx < 1 || nx > n || ny < 1 || ny > m || diTu[nx][ny] == '#' || vis[nx][ny]) {
continue;
}
s[0].push(nx), s[1].push(ny), s[2].push(time + 1);
vis[nx][ny] = true;
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> diTu[i][j];
if (diTu[i][j] == '@') { // 记录起始位置
xx = i;
yy = j;
}
if (diTu[i][j] == '=') { // 记录结束位置
endXX = i;
endYY = j;
}
if (diTu[i][j] >= 'A' && diTu[i][j] <= 'Z') {
int ind = diTu[i][j] - 'A'; // 对应的下标
if (tr[ind].startX == 0) { // 记录传送装置的位置
tr[ind].startX = i;
tr[ind].startY = j;
} else {
tr[ind].endX = i;
tr[ind].endY = j;
}
}
}
}
bfs();
}
第二个测试点数据
10 200
########################################################################################################################################################################################################
=.B####.#.##....#..###.#.#.#######Y#.#.##.####K..I###....####.#####.####.#.#.########.#...#F#####.##..####......#.##.#######..##.#.#######.#..###.#F......P###..##..##..#.###..###.#.####M.#.###.##.####
####.######.D######..#.#####S.####P#...##.##.##########.##.##.####.##...#########.#.##...#..J.#..#.#.#..######.#N####.##.###.....L####.L..#..#EE#..#.#..###.####..#####..#...Q#####.#####K..#.##.####..#
#######.#.#..#.#...###..##I...#####.#####.####..##.#####.#####..#####.##..#..####.#######.....#..##.#####.#####..#...###.....#####.#..#...#.#...G#...###...##...####.#####....#.##########....#####...##
######.#.#..###..##.##.##.#########.####.#.#.#.###.#.#.###..R##.#.####.####.#.#..####..###########.###.##.#.Q###.#.##.##..####..#####.##B###..#..##..#####.###...##..########.####.#.#..###.##J.##..#..#
##X...#.##...###..########...#.#.##.###......#####.#####.#A####.##.#.##.#..###.##..#####....######..#...####..##.#H..#O...###.##..##.####.#.#.##N.#.####.########..####.##.##..###########...##X#..#..##
#####.###..###.###.#####....##.####.####.#.#..#.#..###.###..###.#.#####..###.###...###.#####.####.##.###...#.#..###.#############.##.##..###.#G##.##..######..###.###.#.####.####.###.###.#..##...##.###
###A..##..#####..#..#.###.##...#YC#.#O...##.#..........######.###..#.#.####.###..#######....##..#.###.#..#..#...##.##M..#.#..#...#.##.####.##.#S####.###.##..#.#######.######.#D######.#..#......###..##
######R..#.###.##.#.#.##.###..######.##..#.##..#####..Z###..#H.#.####.#.#.#.#ZC##...#...#.....###.#..###...#####.###..##.####..##.#.##..#####.##########.#.#..#.#...####.####...###...##...#..###.#...@#
########################################################################################################################################################################################################
75