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 的最远距离. 方法參照武森的论文<浅谈 ...
随机推荐
- layui中select的注意
假如不在select 标签里面加上过滤lay-filter 那么你就算怎么绑定事件都是没有任何效果 页面上代码 js文件:
- MFC CListctr显示缩略图
我们知道通过CImageList可以让listctr显示出图片,但是添加的图片大小必须和要CImageList 创建的图片大小一致,才能显示出来.最近遇到一个需求,需要把很多大小不一的jpeg图片通过 ...
- RFID的工作流程
工作流程 1.阅读器通过发射天线发送一定频率的射频信号, 2.当射频卡进入发射天线工作区域时产生感应电流,射频卡获得能量被激活: 3.射频卡将自身编码等信息通过卡内置发送天线发送出去 4.系统接收天线 ...
- 从数据库中生成XML文件
前台页面<%@ page language="java" contentType="text/html; charset=utf-8" pageEncod ...
- unity3d 改动gui label颜色,定义颜色需除以256
GUIStyle titleStyle2 = new GUIStyle(); titleStyle2.fontSize = 20; titleStyle2.normal.textColor = new ...
- react取消监听scroll事件
如果要移除事件addEventListener的执行函数必须使用外部函数而不能直接使用匿名函数 错误写法: // 这样写是移除不了滚动事件的 componentDidMount() { // 添加滚动 ...
- 新版本的AutoCAD2018 怎样删除 A360 Drive盘符
通常的做法,如下: (1)点击开始菜单的“运行”(Win+R或者Win+X快捷选择运行),在弹出的对话框输入“regedit”,回车,进入注册表编辑器. (2)找到HKEY_LOCAL_MACHINE ...
- Library Component Properties的表格如何填写
- 3.Docker安装【Docker每天5分钟】
原文:3.Docker安装[Docker每天5分钟] Docker给PaaS世界带来的“降维打击”,其实是提供了一种非常便利的打包机制.该机制打包了应用运行所需要的整个操作系统,从而保证了本地环境和云 ...
- (素材源代码) 猫猫学IOS(五)UI之360等下载管理器九宫格UI
猫猫分享,必须精品 先看效果 代码学习地址: 猫猫学IOS(五)UI之360等下载管理器九宫格UI 猫猫学IOS(五)UI之360等下载管理器九宫格UI http://blog.csdn.net/u0 ...