您的位置:首页 > 其它

HDU 5626 Clarke and points

2016-02-18 12:18 232 查看
问题描述
克拉克是一名精神分裂患者。某一天克拉克变成了一位几何研究学者。  
他研究一个有趣的距离,曼哈顿距离。点A(x_A, y_A)A(x​A​​,y​A​​)和点B(x_B, y_B)B(x​B​​,y​B​​)的曼哈顿距离为|x_A-x_B|+|y_A-y_B|∣x​A​​−x​B​​∣+∣y​A​​−y​B​​∣。  
现在他有nn个这样的点,他需要找出两个点i, ji,j使得曼哈顿距离最大。


输入描述
第一行是一个整数T(1 \le T \le 5)T(1≤T≤5),表示数据组数。  
每组数据第一行为两个整数n, seed(2 \le n \le 1000000, 1 \le seed \le 10^9)n,seed(2≤n≤1000000,1≤seed≤10​9​​),表示点的个数和种子。  

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


输出描述
对于每组数据输出一行,表示最大的曼哈顿距离。


输入样例
2
3 233
5 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;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: