HDU 5626 Clarke and points

本文介绍了一个关于计算最大曼哈顿距离的问题。患者Clarke患有多重人格障碍,在某一天转变成几何学者,研究如何从随机生成的大量点中找到两两之间的最大曼哈顿距离。文章详细阐述了问题描述、输入输出格式、样例输入输出以及解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Clarke and points


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 127    Accepted Submission(s): 98



Problem Description
Clarke is a patient with multiple personality disorder. One day he turned into a learner of geometric.
He did a research on a interesting distance called Manhattan Distance. The Manhattan Distance between point A(xA,yA) and point B(xB,yB) is |xAxB|+|yAyB| .
Now he wants to find the maximum distance between two points of n points.
 

Input
The first line contains a integer T(1T5) , the number of test case.
For each test case, a line followed, contains two integers n,seed(2n1000000,1seed109) , denotes the number of points and a random seed.
The coordinate of each point is generated by the followed code.

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

Output
For each test case, print a line with an integer represented the maximum distance.
 

Sample Input
  
2 3 233 5 332
 

Sample Output
  
1557439953 1423870062

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

typedef long long ll;
const int maxn = 1000000 + 10;
struct point{
    ll x, y;
}a[maxn];

ll 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,n;
    cin>>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);
        }
        ll xMax = a[0].x + a[0].y, xMin = a[0].x + a[0].y;
        ll yMax = a[0].x - a[0].x, yMin = a[0].x - a[0].y;
        for(int i = 1; i < n; i++){
            ll ax = a[i].x + a[i].y;
            ll in = a[i].x - a[i].y;
            xMax = max(xMax, ax);
            xMin = min(xMin, ax);
            yMax = max(yMax, in);
            yMin = min(yMin, in);
        }
        ll ans = max(abs(xMax - xMin), abs(yMax - yMin));
        cout<<ans<<endl;
    }
    return 0;
}


 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值