After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation.

The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1.

Find the tree that will be the last to start burning. If there are several such trees, output any.

Input

The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers.

The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning.

The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide.

Output

Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any.

Examples

Input
3 3
1
2 2
Output
1 1
Input
3 3
1
1 1
Output
3 3
Input
3 3
2
1 1 3 3
Output
2 2

题意:
给你一个n*m的矩阵,每一个节点表示是一个树,
然后给你k个坐标,表示坐标位置的树着火了,
并且火在蔓延,每一秒火只能蔓延到矩阵内相邻4个位置的树上,
让求最后着火的坐标。
思路:
显然bfs嘛,
queue中加入的是结构体,结构体来维护每一个节点的信息,分别是坐标x,y和第几秒烧到这个树t,然后像四个方向bfs即可。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n,m;
int vis[][];
struct node
{
int x;
int y;
int t;
node(){}
node(int xx,int yy,int tt)
{
x=xx;
y=yy;
t=tt;
}
};
int xx[]={-,,,};
int yy[]={,,-,};
int main()
{
// 注意题目给定了读入和输出的路径。
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
gbtb;
cin>>n>>m;
int k;
cin>>k;
int x,y;
queue<node> q;
int cnt=;
int ansx,ansy;
int mnum=;
repd(i,,k)
{
cin>>x>>y;
vis[x][y]=;
ansx=x;
ansy=y;
q.push(node(x,y,));
}
cnt=k;
node temp;
while(!q.empty())
{
temp=q.front();
q.pop();
repd(i,,)
{
x=temp.x+xx[i];
y=temp.y+yy[i];
if(x>=&&x<=n&&y>=&&y<=m&&vis[x][y]==)
{
cnt++;
if(temp.t+>mnum)
{
mnum=temp.t+;
ansx=x;
ansy=y;
}
vis[x][y]=;
q.push(node(x,y,temp.t+));
}
if(cnt==n*m)// 矩阵中的全部的树都着火过了。优化时间。
{
break;
}
}
} cout<<ansx<<" "<<ansy<<endl; return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
 

最新文章

  1. 网页引用google字体速度慢:fonts.googleapis.com
  2. 通过sqoop来传输mysql/oracle/vertica数据至HBASE
  3. JavaScript对UNIX时间戳的转换
  4. JDK API从下载到使用
  5. .NET VS2012 将代码同步上传到 oschina.net 和 github
  6. 小波说雨燕 第三季 构建 swift UI 之 度假清单 学习笔记
  7. mysqldump备份过程中都干了些什么
  8. EasyUI 格式化DataGrid列
  9. Squid代理之普通代理
  10. Flash AS 响应双击事件MouseEvent.DOUBLE_CLICK
  11. Android——Runtime类中的freeMemory,totalMemory,maxMemory等几个方法
  12. return和break的区别
  13. git常用命令学习(转)
  14. mysql中AES_ENCRYPT、AES_DNCRYPT及CONVERT的用法
  15. selenium中浏览器及对应的驱动(可下载)
  16. Django学习手册 - 基于requests API验证(一)
  17. jmeter接口测试-文件下载
  18. IntelliJ IDEA 下载安装(含注册码)
  19. MySQL日期时间格式化参数
  20. html5 required属性的注意事项

热门文章

  1. mysql的学习笔记(三)
  2. python接口自动化(四)--接口测试工具介绍(详解)
  3. python:socket网络编程
  4. 【网摘】C#中TransactionScope的使用方法和原理
  5. MySql给表添加列和注释
  6. centOS7下Spark安装配置
  7. nginx系列11:负载均衡哈希算法ip_hash与hash模块
  8. 【设计模式】组合模式 Composite Pattern
  9. 放下技术,是PM迈出的第一步
  10. PM意识升级2.0