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
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
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
Several restaurants and hotels may be located near the same crossing.
OutputIn 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) input10 10 2 1 1 3 3 2 1 10 4 4output
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 最遠曼哈頓距離