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

Posted zhchoutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}




以上是关于Codeforces 491B. New York Hotel 最远曼哈顿距离的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #491 (Div. 2) — 赛后补题

Codeforces Round #491 (Div. 2) F. Concise and clear

New York is 3 hours ahead of California

是否有可能两个用户以“America/New_York”格式报告相同的时区名称,但一个正在观察 DST 而另一个不是?

迟到了!!!Taylor Swift -《Welcome To New York》

Codeforces Round #491 (Div. 2) E - Bus Number + 反思