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

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 directorLL 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]

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

  2. HDU 4666 Hyperspace【最远曼哈顿距离+优先队列】

    这个题是动态的求最远曼哈顿距离.做法和POJ 2926 Requirements一样,都是通过二进制枚举符号的情况. 每插入一个节点都要询问最大值和最小值,因此用一个优先队列或者堆维护就可以了. #i ...

  3. 最近/最远曼哈顿距离

    本文都是以二维举例的,实际上变成更多维也是差不多的情况啦,只是每个点的状态多了一些而已. 最远曼哈顿距离: 假设有两个点A(xi,yi),B(xj,yj) 则两点之间的曼哈顿距离为 |xi-xj|+| ...

  4. HDU - 6435 Problem J. CSGO 多维最远曼哈顿距离+原理 2018多校-10

    题意: 给定 n个物品A 和 m个物品B:每个物品都有一个值 s 和 k 个属性值 x[i], 问:从n个物品中选一个 i,m个物品里选一个 j,ans = i_s + j_s + Sigma( | ...

  5. Codeforces 685C Optimal Point (二分、不同类型距离的相互转换)

    题目链接 https://codeforces.com/contest/685/problem/C 题解 我怎么又还差最后一步的时候放弃了然后往别的方向上想了一小时才发现这个思路能做-- 首先二分答案 ...

  6. 曼哈顿距离与切比雪夫距离的转化及prufer序列

    目录 曼哈顿距离与切比雪夫距离的相互转化 prufer序列 1. 曼哈顿距离 与 切比雪夫距离 的相互转化 曼哈顿距离 |x1−x2|+|y1−y2|=max(x1−x2+y1−y2,x1−x2−y1 ...

  7. 图论 —— 生成树 —— 曼哈顿距离最小生成树

    [概述] 当给出一些二维平面的点时,记两点间距离为曼哈顿距离,此时的最小生成树,称为曼哈顿最小距离生成树. 对于 n 个点来说,最朴素的做法是暴力求出所有所有点两两之间的曼哈顿距离,然后再跑最小生成树 ...

  8. 简单粗暴理解与实现机器学习之K-近邻算法(三):距离度量、欧氏距离、曼哈顿距离、切比雪夫距离、闵可夫斯基距离、标准化距离、余弦距离、汉明距离、杰卡德距离、马氏距离

    K-近邻算法 文章目录 K-近邻算法 学习目标 1.3 距离度量 1 欧式距离**(Euclidean Distance):** 2 **曼哈顿距离(Manhattan Distance):** 3 ...

  9. 各种距离 欧式距离、曼哈顿距离、切比雪夫距离、闵可夫斯基距离、标准欧氏距离、马氏距离、余弦距离、汉明距离、杰拉德距离、相关距离、信息熵...

    1. 欧氏距离(Euclidean Distance) 欧氏距离是最容易直观理解的距离度量方法,我们小学.初中和高中接触到的两个点在空间中的距离一般都是指欧氏距离. 二维平面上点a(x1,y1)与b( ...

最新文章

  1. ORACLE数据库系统结构
  2. ionic项目相关的操作命令
  3. 78折用计算机怎么算,一分钟速算口诀,计算速度秒杀计算器
  4. VMware安装Centos7后有线线缆被拔出
  5. Linux基金会亚太区与开源中国达成战略合作 共同推动中国开源人才培养
  6. 单词的长度(信息学奥赛一本通-T1142)
  7. GprMax 3.1.5 建模的in文件编写详解(2)
  8. sender分析之Selector
  9. vb中WindowsMediaPlayer的常用属性和方法
  10. 浅析那些带着“主角光环“的泰坦尼克号幸存者(下)
  11. 【信号检测】基于matlab双稳态随机共振的参数寻优算法【含Matlab源码 1700期】
  12. 碰撞检测之 AABB 包围盒
  13. Python实现的简易HTTP代理服务器
  14. 新交规驾驶证扣分什么时候清零
  15. 《书生云超融合一体机》T-CAM评审会召开
  16. 学习自旋电子学的笔记06:“扫参数”批量微磁模拟,ubermag介绍,微磁模拟求助
  17. win10 iso安装包中的两个setup.exe如何使用
  18. Office2010 把多个excel合并成一个
  19. 图机器学习(GML)图神经网络(GNN)原理和代码实现(前置学习系列二)
  20. 2023MathorCup 高校数学建模挑战赛D题思路解析

热门文章

  1. java验证码识别--2
  2. CSS如何设置高度为屏幕高度_(15)让这些“展示”有更好的扩展性——媒体查询 | CSS...
  3. MYSQL数据库VALUES_MySQL数据库“十宗罪”(十大经典错误案例)
  4. Xcode下载安装问题
  5. QT Media Error: DirectShowPlayerService::doRender: Unresolved error code 0x80040266
  6. 生信多组学整合工具的比较研究
  7. VS2017配置opencv教程(图文详解)
  8. 音频录入后以不同采样率输出
  9. win7 安装c语言环境变量,win7下如何配置编程环境变量的方法
  10. js实现kmp算法_「leetcode」459.重复的子字符串:KMP算法还能干这个!