日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces 491B. New York Hotel 最远曼哈顿距离

發(fā)布時間:2025/3/8 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces 491B. New York Hotel 最远曼哈顿距离 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


最遠曼哈頓距離有兩個性質(zhì):

1: 對每一個點(x,y) ?分別計算 ?+x+y , -x+y , x-y , -x-y 然后統(tǒng)計每種組合的最大值就能夠了, 不會對結(jié)果產(chǎn)生影響

2: 去掉絕對值 , 設(shè)正號為0負號為1 則 兩個點的符號是能夠通過異或的得到的.?

如兩個點 P(x,y) 和 Q(a,b) 若去掉絕對值符號后P的兩個坐標(biāo)為 -x +y 既相應(yīng)數(shù)字 10 ?那么Q相應(yīng)的數(shù)字則為 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?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.

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; }



總結(jié)

以上是生活随笔為你收集整理的Codeforces 491B. New York Hotel 最远曼哈顿距离的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。