这评分不做评价
查看原帖
这评分不做评价
565707
mediocre_楼主2024/8/28 19:49
#include <bits/stdc++.h>
using namespace std;
const int fx[4] = {1, -1, 0, 0};
const int fy[4] = {0, 0, 1, -1};
const int N = 1005;
int n, sx, sy, vis[N][N], maxx, maxy;
bool mapp[N][N];
struct Node {
	int x, y;
} ;
queue <Node> q;
int main() {
	scanf("%d%d%d", &n, &sx, &sy);
	while (n--) {
		int x, y;
		scanf("%d%d", &x, &y);
		maxx = max(maxx, x);
		maxy = max(maxy, y);
		mapp[x][y] = 1;
	}
	q.push({sx, sy});
	memset(vis, 0x7f, sizeof(vis));
	vis[sx][sy] = 0;
	while (!q.empty()) {
		Node u = q.front();
		q.pop();
		for (int d = 0; d < 4; ++d) {
			int nx = u.x + fx[d];
			int ny = u.y + fy[d];
			int now = vis[u.x][u.y];
			if (mapp[nx][ny]) ++now;
			if (vis[nx][ny] <= now) continue;
			vis[nx][ny] = now;
			q.push({nx, ny});
		}
	}
	printf("%d", vis[0][0]);
	return 0;
}

因为 x0,y0≤1000x_0,y_0 \le 1000 所以这道题可以朴素bfs过

然后评蓝真的唐了把

2024/8/28 19:49
加载中...