HDU 5626 Clarke and points 求平面最远哈曼顿距离

题意:根据题意给一个函数能得到一个点的数组,然后求所有点中最远的哈曼顿距离
思路:哈曼顿距离是|Xa-Xb|+|Ya-Yb|,这里看数据就知道不能裸跑,我们可以讨论绝对值内的正负,然后会出现四种情况,整理得到(Xa+Ya)-(Xb+Yb),(Xa-Ya)-(Xb-Yb),(-Xa+Ya)-(-Xb+Yb),(-Xa-Ya)-(-Xb-Yb)
(比赛的时候稍微算了一下,感觉nlogn能过,然后就T了QAQ
这里保存一下每个状态的最大最小就OK了

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<string>
#include<vector>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm> 
using namespace std;
typedef long long LL;
#define maxn 1000005
#define f(x) (x*1.0)
#define inf 0x7fffffff
#define maxm maxn*maxn
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define lowbit(x) (x&(-x))
#define cheak(i) printf("%d ",i)
#define lson(x) (splay[x].son[0])
#define rson(x) (splay[x].son[1])
#define rfor(i,a,b) for(i=a;i<=b;++i)
#define lfor(i,a,b) for(i=a;i>=b;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define mec(a,b) memcpy(a,b,sizeof(b))
struct node
{
    LL x,y;
}A[maxn];
LL B[maxn];
long long seed;
inline long long rand(long long l, long long r) {
    static long long mo=1e9+7, g=78125;
    return l+((seed*=g)%=mo)%(r-l+1);
}

int main()
{
    int T,i;
    LL n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&n,&seed);
        LL Min1=inf,Min2=inf,Min3=inf,Min4=inf,Max1=-inf,Max2=-inf,Max3=-inf,Max4=-inf;
        rfor(i,1,n)
        {
            A[i].x = rand(-1000000000, 1000000000),
            A[i].y = rand(-1000000000, 1000000000);
            Min1=min(Min1,A[i].x+A[i].y);Max1=max(Max1,A[i].x+A[i].y);
            Min2=min(Min2,A[i].x-A[i].y);Max2=max(Max2,A[i].x-A[i].y);
            Min3=min(Min3,-A[i].x+A[i].y);Max3=max(Max3,-A[i].x+A[i].y);
            Min4=min(Min4,-A[i].x-A[i].y);Max4=max(Max4,-A[i].x-A[i].y);
            //printf("%lld %lld\n",A[i].x,A[i].y);
        }
        LL ans=0;
        ans=max(ans,Max1-Min1);
        ans=max(ans,Max2-Min2);
        ans=max(ans,Max3-Min3);
        ans=max(ans,Max4-Min4); 
        printf("%lld\n",ans);
    }
    return 0;
}

你可能感兴趣的:(HDU,哈曼顿距离)