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

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 ≤ N, 1 ≤ 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 最远曼哈顿距离的更多相关文章

  1. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  2. poj 2926:Requirements(最远曼哈顿距离,入门题)

    Requirements Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3908   Accepted: 1318 Desc ...

  3. POJ-2926 Requirements 最远曼哈顿距离

    题目链接:http://poj.org/problem?id=2926 题意:求5维空间的点集中的最远曼哈顿距离.. 降维处理,推荐2009武森<浅谈信息学竞赛中的“0”和“1”>以及&l ...

  4. [HDU 4666]Hyperspace[最远曼哈顿距离][STL]

    题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...

  5. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  6. HDU 4666 最远曼哈顿距离

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...

  7. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  8. 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)

    有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...

  9. CF 366E - Dima and Magic Guitar 最远曼哈顿距离

    题目:http://codeforces.com/problemset/problem/366/E 事实上就是找 n * m 矩阵中数字 x 和 数字 y 的最远距离. 方法參照武森的论文<浅谈 ...

随机推荐

  1. Codeforces Round #194 (Div. 2) 部分题解

    http://codeforces.com/contest/334 A题意:1-n^2 平均分成 n 份,每份n个数,且和相同 解法 : 构造矩阵1-n^2的矩阵即可 ][]; int main() ...

  2. HTML基础第十讲---排版卷标

    转自:https://i.cnblogs.com/posts?categoryid=1121494 网页的排版部份也是很重要的一环,有些现成的卷标就可以让您轻易的完成缩排或是一些特殊格式的编排喔! [ ...

  3. php编译参数注释

    1. 指定安装路径 --prefix=PREFIX 2. 指定运行用户 --with-fpm-user=nginx 3. 指定运行组 --with-fpm-group=nginx 3.与'--pref ...

  4. Python 极简教程(八)字符串 str

    由于字符串过于重要,请认真看完并保证所有代码都至少敲过一遍. 对于字符串,前面在数据类型中已经提到过.但是由于字符串类型太过于常用,Python 中提供了非常多的关于字符串的操作.而我们在实际编码过程 ...

  5. 图像处理 Mine

    1)中值滤波:排序取中间值.作用:去噪点 1.1)均值滤波; 1.2)高斯模糊:执行高斯模糊,然后改混合模式,改成叠加.柔光或者深色.就能得到平滑而不模糊的效果. 2)腐蚀.膨胀:开运算(腐蚀后膨胀) ...

  6. struts2_7_Action类中方法的动态调用

    (一)直接调用方法(不推荐使用) 1)Action类: private String savePath; public String getSavePath() { return savePath; ...

  7. Eclipse 出错 Error:Could not create the Java Virtual Machine Error:A fatal exception has occurred

    提示如下: scala compile server. error:could not create the java machine.Error: A fatal exception has occ ...

  8. C#添加水印

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  9. linux中内存泄漏的检測(一)最简单的方法

    什么是内存泄漏 内存泄漏是指程序动态申请的内存在使用完后没有释放,导致这段内存不能被操作系统回收再利用. 比如这段程序,申请了4个字节的空间但没有释放,有4个字节的内存泄漏. #include < ...

  10. 基于phonegap开发app的实践

    app开发告一段落.期间遇到不少问题,写篇文章记录一下. 为虾米要用phonegap 开发app,至少要考虑android和ios两个版本号吧,android偶能够应付,ios表示全然木有接触过.于是 ...