题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
using PII = pair<int, int>;
const int N = 2020;
int dist[N][N];
queue<PII>q;
int n, m;
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };
int k;
void solve()
{
while (!q.empty())
{
auto t = q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
int x = t.first + dx[i];
int y = t.second + dy[i];
if (x >= 1 && x <= n && y >= 1 && y <=m && dist[x][y] == -1)
{
dist[x][y] = dist[t.first][t.second] + 1;
q.push({ x,y });
}
}
}
}
int main()
{
memset(dist, -1, sizeof dist);
cin >> n >> m;
cin >> k;
while (k--)
{
int i, j;
cin >> i >> j;
q.push({ i,j });
dist[i][j] = 0;
// cout << i << " " << j << endl;
}
solve();
PII res;
int mi = -1e6;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (dist[i][j] != -1)
{
if (dist[i][j] > mi)
{
mi = dist[i][j];
res.first = i;
res.second = j;
}
}
}
cout << res.first << " " << res.second ;
return 0;
}