知识点:广搜
难度:5
这个题给的难度5实际是虚高了,顶多是个绿题,CF的分是1500,还是比较准确的,这个就是一个裸的bfs,是个多源的bfs,然后我们广搜的时候每次出队的时候更新一下答案就行了,那么最后一定是最后才覆盖的点
然后就是这个题是啥标准输入输出啥的,需要在程序里面加上那个玩意儿,这个我记得学c语言的时候用到了,但是现在已经往的差不多了
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
struct node {
int x, y;
node() {}
node(int a, int b): x(a), y(b) {}
} ans;
int n, m, k, a[10], b[10], dist[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs() {
queue<node> q;
memset(dist, -1, sizeof(dist));
for (int i = 0; i < k; i++) {
q.push(node(a[i], b[i]));
dist[a[i]][b[i]] = 0;
}
while (!q.empty()) {
node now = q.front(); q.pop();
ans = now;
for (int i = 0; i < 4; i++) {
int x1 = now.x + dx[i];
int y1 = now.y + dy[i];
if (x1 < 1 || x1 > n || y1 < 1 || y1 > m) continue;
if (dist[x1][y1] == -1) {
q.push(node(x1, y1));
dist[x1][y1] = dist[now.x][now.y] + 1;
}
}
}
}
int main() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> n >> m >> k;
for (int i = 0; i < k; i++) {
cin >> a[i] >> b[i];
}
bfs();
cout << ans.x << " " << ans.y;
return 0;
}