codeForces 35C

Description

input
input.txt
output
output.txt

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.

Sample Input

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
//广度优先搜索,分别从几个着火点开始搜索,初始化其他树木着火事件为无穷。如果遇到一棵可以更新(变少)着火时间的树木,那么就将这棵树推入队列。。。。此题也是文本读入文本读出
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
#define maxn 2008
bool map[2008][2008];
int dis[maxn][maxn];
int xx[12];
int yy[12];
int heng[]={0,0,1,-1};
int zong[]={1,-1,0,0};
inline int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n,m;
	while(scanf("%d%d",&n,&m)==2)
	{
		memset(dis,0x3f,sizeof(dis));
		memset(map,0,sizeof(map));
		int k;
		scanf("%d",&k);
		for(int i=1;i<=k;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			xx[i]=x;
			yy[i]=y;
			map[x][y]=1;
			dis[x][y]=0;
		}
		for(int i=1;i<=k;i++)
		{
			queue <int> qx;
			queue <int> qy;
			qx.push(xx[i]);//xx[i]代表是行数
			qy.push(yy[i]);
			while(!qx.empty())
			{
				int xxx=qx.front();
				int yyy=qy.front();
				qx.pop();
				qy.pop();
				map[xxx][yyy]=1;
				for(int j=0;j<4;j++)
				{
					int x_=xxx+heng[j];
					int y_=yyy+zong[j];
					if((x_>=1&&x_<=n)&&(y_>=1&&y_<=m))
					{
						if(dis[xxx][yyy]+1<dis[x_][y_])
						{
							dis[x_][y_]=dis[xxx][yyy]+1;
							qx.push(x_);
							qy.push(y_);
						}
					}
				}
			}
		}
		int las=-1;
		int lasx,lasy;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(dis[i][j]>las)
				{
					las=dis[i][j];
					lasx=i;
					lasy=j;
				}
			}
		}
		cout<<lasx<<" "<<lasy<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值