题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5626
Clarke and points
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 307 Accepted Submission(s): 220
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.
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);
```
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
Source
//可以直接看代码:
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define maxn 1100000
long long x[maxn],y[maxn];
long long seed,n;
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;
cin>>T;
while(T--)
{
cin >> n >> seed;
for(int i=0; i<n; i++)
{
x[i] = rand(-1000000000, 1000000000),
y[i] = rand(-1000000000, 1000000000);
}
//printf("%I64d %I64d\n", x[n-1], y[n-1]);
long long pma=-1e18,pmi=1e18,mma=-1e18,mmi=1e18;//以下是关键代码
long long ans = -1e18;
for(int i=0; i<n; i++)
{
pma=max(pma,x[i]+y[i]);
pmi=min(pmi,x[i]+y[i]);
mma=max(mma,x[i]-y[i]);
mmi=min(mmi,x[i]-y[i]);
}
ans = max(ans, pma-pmi);
ans = max(ans, mma-mmi);
cout<< ans<<endl;
}
return 0;
}