HDU Clarke and points

Clarke and points

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 429 Accepted Submission(s): 300

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 |xA−xB|+|yA−yB|.
Now he wants to find the maximum distance between two points of n points.

Input
The first line contains a integer T(1≤T≤5), the number of test case.
For each test case, a line followed, contains two integers n,seed(2≤n≤1000000,1≤seed≤109), 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

题意就是求哈曼顿距离的最大值
d=|Xa-Xb|+|Ya-Yb| 考虑去绝对值就好了
如果Xa>Xb&&Ya>Yb 就直接去绝对值好了
式子就变成了(Xa+Ya) - (Xb+Yb)
这就好办了找到最大的X+Y 和最小的X+Y就好了
Xa

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
const long long inf=1e9+10;
long long seed;
int x[1000010];
int y[1000010];
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; scanf("%d", &T);
    while(T--){
        long long x,y,xa=-inf,ya=inf,xb=-inf,yb=inf;
        int n; scanf("%d %lld", &n, &seed);
        for (int i = 0; i < n; i++){
            x = rand(-1000000000, 1000000000),
            y = rand(-1000000000, 1000000000);
            xa=max(xa,x+y);
            ya=min(ya,x+y);
            xb=max(xb,x-y);
            yb=min(yb,x-y);
        }
        long long ans=max(xa-ya,xb-yb);
        printf("%lld\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值