#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≤1000 所以这道题可以朴素bfs过
然后评蓝真的唐了把