• 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 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 ≤ N1 ≤ 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 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;
    }
    




  • 相关阅读:
    vb.net structure 定义静态数组
    调色板原理 & 编程
    CView::OnPreparePrinting
    MFC单文档程序架构解析
    基于Eclipse远程调试解决的预上线首页打开特别慢的问题
    Shiro Filter引发的思考
    Shiro Filter中利用Callable和Runnable的委派模式
    Shiro DefaultFilter
    防止Form表单重复提交的客户端及服务器端的方式
    Shiro Filter的设计概念
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7396646.html
Copyright © 2020-2023  润新知