HDU 5626 Clarke and points

来源:互联网 发布:canon mp236清零软件 编辑:程序博客网 时间:2024/06/07 09:20
问题描述
克拉克是一名精神分裂患者。某一天克拉克变成了一位几何研究学者。  他研究一个有趣的距离,曼哈顿距离。点A(x_A, y_A)A(xA,yA)和点B(x_B, y_B)B(xB,yB)的曼哈顿距离为|x_A-x_B|+|y_A-y_B|xAxB+yAyB。  现在他有nn个这样的点,他需要找出两个点i, ji,j使得曼哈顿距离最大。  
输入描述
第一行是一个整数T(1 \le T \le 5)T(1T5),表示数据组数。  每组数据第一行为两个整数n, seed(2 \le n \le 1000000, 1 \le seed \le 10^9)n,seed(2n1000000,1seed109),表示点的个数和种子。  nn个点的坐标是这样得到的: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);}// ...cin >> n >> seed;for (int i = 0; i < n; i++)x[i] = rand(-1000000000, 1000000000),y[i] = rand(-1000000000, 1000000000);
输出描述
对于每组数据输出一行,表示最大的曼哈顿距离。
输入样例
23 2335 332
输出样例
1557439953

1423870062

统计最大和最小的x+y和x-y就好了

#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<functional>using namespace std;typedef unsigned long long ull;typedef long long LL;const int maxn = 1e6 + 10;const int mod = 1e9 + 7;int T, n;LL seed, mina, minb, maxa, maxb;struct point{    LL x, y;    bool operator<(const point&a)const    {        return x == a.x ? x < a.x : y < a.y;    }}a[maxn];inline LL 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(){    scanf("%d", &T);    while (T--)    {        cin >> n >> seed;        for (int i = 0; i < n; i++)        {            a[i].x = rand(-1000000000, 1000000000);            a[i].y = rand(-1000000000, 1000000000);        }        maxa = mina = a[0].x + a[0].y;        maxb = minb = a[0].x - a[0].y;        for (int i = 1; i < n; i++)        {            mina = min(mina, a[i].x + a[i].y);            minb = min(minb, a[i].x - a[i].y);            maxa = max(maxa, a[i].x + a[i].y);            maxb = max(maxb, a[i].x - a[i].y);        }        cout << max(maxb - minb, maxa - mina) << endl;    }        return 0;}


0 0