CE求调
查看原帖
CE求调
1398441
yinziyi_5033楼主2024/8/3 16:52

代码一堆离奇的报错

#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;
}
2024/8/3 16:52
加载中...