yinziyi_5033 @ 2024-08-03 16:52:19
代码一堆离奇的报错
#include<bits/stdc++.h>
using namespace std;
int n, x1, y1, x2, y2;
char g[1005][1005];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
struct node {
int x, y, step;
};
void bfs() {
queue<node>q;
q.push(node{ x1,y1,0 });
g[x1][y1] = '1';
while (!q.empty()) {
node now = q.front();
q.pop();
if (now.x == x2 && now.y == y2) {
cout << now.step;
return;
}
for (int i = 0; i < 4; i++) {
node next = node{ now.x + dx[i],now.y + dy[i],now.step + 1 };
if (next.x >= 1 && next.x <= n && next.y >= 1 && next.y <= n && g[next.x][next.y] == '0') {
q.push(next);
g[next.x][next.y] = '1';
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) cin >> g[i][j];
}
cin >> x1 >> y1 >> x2 >> y2;
bfs();
return 0;
}
by HNOIRPplusplus @ 2024-08-03 16:54:12
@yinziyi_5033 y1 在万能头里面的某一个头文件里面声明用作别的内容了。因此你不能再声明一次了。
by liumuxian @ 2024-08-03 16:55:01
y1 是c++的一个关键字,不能用 y1 做一个变量或者数组的名字,换一个就好了,比如说 y3 y 4 之类的
by liumuxian @ 2024-08-03 16:55:37
求关注QWQ