hdu 5626 数学题

Clarke and points

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
分析得所有x和y都为负数
将|xa-xb|+|ya-yb|->(xb+yb)-(xa+ya)和(xb-yb)-(xa-ya)
记录这四个最小最大值,然后求dis即可(ps:这是我在hdu上排名最靠前的一道题有前5小兴奋。。。虽然是新题现在交的人不多。。但是让我享受一下这种感觉吧。。。orz)

上代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long int ll;
ll n;
long long seed;
ll maxx,minx,maxy,miny;
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);
}
ll x,y;
ll m[5];
void init(ll n)
{
    m[1]=m[3]=10000000000;
    m[2]=m[4]=-10000000000;
    for (ll i = 0; i < n; i++)
    {x = rand(-1000000000, 1000000000),
    y = rand(-1000000000, 1000000000);
    m[1]=min(m[1],x+y);
    m[2]=max(m[2],x+y);
    m[3]=min(m[3],x-y);
    m[4]=max(m[4],x-y);
    }

}
ll dis;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
{
scanf("%I64d%I64d",&n,&seed);
init(n);
dis=-1;
dis=max(dis,(ll)fabs(m[1]-m[2]));
dis=max(dis,(ll)fabs(m[3]-m[4]));
printf("%d\n",dis);}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值