不知道自己的bfs哪里错了... 朴素bfs,求大佬帮调试呜呜呜呜 (**码风勉强看看吧T-T)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 501, dir[5][2] = {{0, 0}, {-1, 0}, {1, 0}, {0, -1}, {0, 1}};
struct node {
int x, y, Sx, Sy, Mx, My;
int t, td = 0;
inline int dis() { return sqrt(pow(x-Sx, 2) + pow(y-Sy, 2)); }
} start;
int n, m, s, d, len[2];
string str[2]; // 0: S 1: M
bitset<MAXN> mapp[MAXN];
inline bool bad(int x, int y) { return x < 1 || x > n || y < 1 || y > m || mapp[x][y]; }
inline int bfs() {
queue<node> q;
q.push(start);
node now, nxt;
while(!q.empty()) {
nxt = now = q.front(); q.pop();
nxt.t++;
nxt.Sx += dir[str[0][nxt.t%len[0]]][0], nxt.Sy += dir[str[0][nxt.t%len[0]]][1];
if(bad(nxt.Sx, nxt.Sy)) nxt.Sx = now.Sx, nxt.Sy = now.Sy;
nxt.Mx += dir[str[1][nxt.t%len[1]]][1], nxt.My += dir[str[1][nxt.t%len[1]]][1];
if(bad(nxt.Mx, nxt.My)) nxt.Mx = now.Mx, nxt.My = now.My;
for(int i = 0;i < 5;i++) {
nxt.x = now.x + dir[i][0], nxt.y = now.y + dir[i][1];
if(bad(nxt.x, nxt.y)) continue;
if(nxt.dis() > d) {
nxt.td = now.td + 1;
if(nxt.td > s) continue;
} else nxt.td = 0;
if(nxt.x == nxt.Mx && nxt.y == nxt.My) return nxt.t;
q.push(nxt);
}
}
return -1; // Let warning stay AWAY from me!
}
signed main() {
cout.tie(0), cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> s >> d;
string c;
for(int i = 1; i <= n; i++) {
cin >> c;
for(int j = 1; j <= m; j++) mapp[i][j] = c[j-1] ^ 48;
}
cin >> start.Sx >> start.Sy >> start.Mx >> start.My >> str[0] >> str[1];
len[0] = str[0].size(), len[1] = str[1].size();
start.x = start.Sx, start.y = start.Sy, start.t = 0;
cout << bfs();
return 0;
}