Codeforces 491B. New York Hotel 最远曼哈顿距离


最远曼哈顿距离有两个性质:

1: 对每个点(x,y)  分别计算  +x+y , -x+y , x-y , -x-y 然后统计每种组合的最大值就可以了, 不会对结果产生影响

2: 去掉绝对值 , 设正号为0负号为1 则 两个点的符号是可以通过异或的得到的. 

如两个点 P(x,y) 和 Q(a,b) 若去掉绝对值符号后P的两个坐标为 -x +y 既对应数字 10  那么Q对应的数字则为 01 既 +a -b 两个点的曼哈顿距离为 -x +y +a -b

B. New York Hotel
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 toMC friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street-avenue crossings. They also want that the maximum distance covered by one of them while traveling to the restaurant to be minimum possible. Help friends choose optimal restaurant for a celebration.

Suppose that the distance between neighboring crossings are all the same equal to one kilometer.

Input

The first line contains two integers N и M — size of the city (1 ≤ N, M ≤ 109). In the next line there is a single integer C (1 ≤ C ≤ 105) — the number of hotels friends stayed at. Following C lines contain descriptions of hotels, each consisting of two coordinates x and y (1 ≤ x ≤ N1 ≤ y ≤ M). The next line contains an integer H — the number of restaurants (1 ≤ H ≤ 105). Following H lines contain descriptions of restaurants in the same format.

Several restaurants and hotels may be located near the same crossing.

Output

In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them.

Sample test(s)
input
10 10
2
1 1
3 3
2
1 10
4 4
output
6
2



/* ***********************************************
Author        :CKboss
Created Time  :2015年03月13日 星期五 20时17分17秒
File Name     :CF491B.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long int LL;

const LL INF=1LL<<60;

LL n,m;
LL C,H;
LL a00,a01,a10,a11;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	cin>>n>>m;
	cin>>C;
	bool first=true;
	while(C--)
	{
		LL x,y;
		cin>>x>>y;
		if(first) 
		{
			first=false;
			a00=x+y; a10=-x+y; a01=x-y; a11=-x-y; 
		}
		else
		{
			a00=max(a00,x+y); a10=max(a10,-x+y); 
			a01=max(a01,x-y); a11=max(a11,-x-y); 
		}
	}

	LL d=INF,pos,cnt=1;

	cin>>H;
	while(H--)
	{
		LL x,y;
		cin>>x>>y;

		/// four director
		LL mx = max( max( x+y+a11, -x-y+a00 ) , max( -x+y+a01 , x-y+a10 ) );
		if(mx<d) { d=mx; pos = cnt; }
		cnt++;
	}

	cout<<d<<endl<<pos<<endl;

    return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值