莫名RE
查看原帖
莫名RE
306962
MVP_Harry楼主2020/5/22 07:31

我一看这不是一道BFS板子题吗,但一直RE,非常困惑,求大佬解惑

#include<bits/stdc++.h>

using namespace std;

#define rep(i, m, n) for(int i = m; i <= n; i++)

int n, vis[10005][10005], sx, sy, ex, ey, ans;
char mp[10005][10005];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

struct node {
	int x, y, dis;
};

void bfs(int x, int y) {
	vis[x][y] = 1;
	queue<node> q;
	q.push((node){x, y, 0});
	while (!q.empty()) {
		node temp = q.front();
		q.pop();
		rep(i, 0, 4) {
			int xx = temp.x + dx[i], yy = temp.y + dy[i];
			if (!vis[xx][yy] && xx >= 0 && xx <= n - 1 && yy >= 0 && yy <= n - 1 && mp[xx][yy] == '0') {
				vis[xx][yy] = 1;
				q.push((node){xx, yy, temp.dis + 1});
			}
		}
		if (temp.x == ex - 1 && temp.y == ey - 1) {
			ans = temp.dis;
		}
	}

}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	cout << n << endl;
	rep(i, 0, n - 1) {
		cin >> mp[i];
	}
	cin >> sx >> sy >> ex >> ey;
	bfs(sx - 1, sy - 1);
	cout << ans << endl;
	return 0;
}


2020/5/22 07:31
加载中...