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
2 seconds
256 megabytes
standard input
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 toM. C 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.
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.
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.
10 10
2
1 1
3 3
2
1 10
4 4
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 最远曼哈顿距离的更多相关文章
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- poj 2926:Requirements(最远曼哈顿距离,入门题)
Requirements Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3908 Accepted: 1318 Desc ...
- POJ-2926 Requirements 最远曼哈顿距离
题目链接:http://poj.org/problem?id=2926 题意:求5维空间的点集中的最远曼哈顿距离.. 降维处理,推荐2009武森<浅谈信息学竞赛中的“0”和“1”>以及&l ...
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...
- HDU 4666 Hyperspace (最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 最远曼哈顿距离
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)
有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
题目:http://codeforces.com/problemset/problem/366/E 事实上就是找 n * m 矩阵中数字 x 和 数字 y 的最远距离. 方法參照武森的论文<浅谈 ...
随机推荐
- BZOJ3926: [Zjoi2015]诸神眷顾的幻想乡(广义后缀自动机)
Description 幽香是全幻想乡里最受人欢迎的萌妹子,这天,是幽香的2600岁生日,无数幽香的粉丝到了幽香家门前的太阳花田上来为幽香庆祝生日. 粉丝们非常热情,自发组织表演了一系列节目给幽香看. ...
- Robot Framework初步使用
第一步,新建一个Project:
- 【hdu 1533】Going Home
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=1533 [题意] 一个N*M地图上有相同数量的字符H和字符m,m代表一个 人,H代表一个房子.人到房子的花 ...
- servlet、filter、listener继承的基类和获得作用域的方式
一.servlet: 1.servlet属于j2ee的组件,构建servlet的web project不需要导入项目框架jar包 2.servlet的体系结构: 在j2ee API中,提供给serv ...
- 16、cgminer学习之:pthread_mutex_init和pthread_cond_init
1.原理 假设有两个线程同时访问一个全局变量 n,这个全局变量的初始值等于0. Int n = 0 ; 消费者线程 A 进入临界区,访问 n,A 必须等到 n 大于 0 才能接着往下执行,如果 n= ...
- 1.1 Python基础知识 - 变量
1.什么是变量? 变量是可以通过变量名访问的内存地址,变量通常是可变的. 2.怎样去定义? 变量格式: 变量名 = "变量值" 例如: name = "Zhanghk&q ...
- 2013腾讯编程马拉松初赛第〇场(HDU 4503) 湫湫系列故事——植树节
http://acm.hdu.edu.cn/showproblem.php?pid=4503 题目: 已知湫湫的班里共有n个孩子,每个孩子有Bi个朋友(i从1到n),且朋友关系是相互的,如果a小朋友和 ...
- Spring Boot中的缓存支持(一)注解配置与EhCache使用
Spring Boot中的缓存支持(一)注解配置与EhCache使用 随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决 ...
- 第一个hello word 驱动载入失败--------
今天尝试自己载入第一个驱动模块,依据惯例hello word 然后失败了,如今说明我的操作过程.请个位看看. 首先我的内核版本号: 模块代码与MAKEFILE #include<linux/in ...
- Unity自带网络功能——NetworkView组件、Serialize、RPC
Unity拥有大量的第三方插件,专门提供了对网络功能的支持.可是,大部分开发人员第一次接触到的还是Unity自带的网络功能,也就是大家常常说到的Unity Networking API.这些API是借 ...