RE???
查看原帖
RE???
923248
Lian_zy楼主2023/11/21 17:02

洛谷IDE RE,DEV-C++给了一堆警告还没法正常输出结果

#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 5e5 + 10;
queue<int> qx, qy;
bool vis[maxn][maxn];
int n, m, a, b, tx, ty, nx, ny, dis[maxn][maxn];
int main() {
	scanf("%d %d %d %d", &n, &m, &a, &b);
	while (a--) {
		scanf("%d %d", &tx, &ty);
		vis[tx][ty] = true;
		qx.push(tx), qy.push(ty);
	}
	while (qx.size()) {
		tx = qx.front();
		ty = qy.front();
		for (int i = -1; i <= 1; i++) {
			for (int j = -1; j <= 1; j++) {
				nx = tx + i;
				ny = ty + j;
				if (i == j || nx < 1 || nx > n || ny < 1 || ny < m || vis[nx][ny]) continue;
				vis[nx][ny] = true;
				qx.push(nx), qy.push(ny);
				dis[nx][ny] = dis[tx][ty] + 1;
			}
		}
		qx.pop();
		qy.pop();
	}
	while (b--) {
		scanf("%d %d", &tx, &ty);
		printf("%d\n", dis[tx][ty]);
	}
	return 0;
}
2023/11/21 17:02
加载中...