您的位置:首页 > 其它

hdu 5626 数学题

2016-02-16 16:30 316 查看
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);}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数学