码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-19 15:51:29      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:friend   article   orm   director   rda   distance   algo   else   mil   


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

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 最远曼哈顿距离

标签:friend   article   orm   director   rda   distance   algo   else   mil   

原文地址:http://www.cnblogs.com/zhchoutai/p/7396646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!