Clarke and points
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 380 Accepted Submission(s): 268
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
Recommend
万万没想到坐标的产生直接复制粘贴题目上的代码即可,我愣是被唬住了;
把带绝对值的全部拆开,就是四个表达式;
把这四个表达式的最大值求出来,再比较一下大小,答案就出来了;
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<iomanip>
#include<map>
#include<set>
#include<functional>
#define pi 3.14159265358979323846
using namespace std;
long long int n;
long long seed;
long long int ans;
long long int x,y;
long long int Max[5];
long long int Min[5];
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--)
{
ans=0;
for(int i=0;i<5;++i)
{
Max[i]=-1e17;
Min[i]=1e17;
}
cin >> n >> seed;
for (int i = 0; i < n; i++)
{
x = rand(-1000000000, 1000000000);
y = rand(-1000000000, 1000000000);
Max[0]=max(Max[0],x+y);
Max[1]=max(Max[1],x-y);
Max[2]=max(Max[2],-x+y);
Max[3]=max(Max[3],-x-y);
Min[0]=min(Min[0],x+y);
Min[1]=min(Min[1],x-y);
Min[2]=min(Min[2],-x+y);
Min[3]=min(Min[3],-x-y);
}
for(int i=0;i<4;++i)
ans=max(ans,Max[i]-Min[i]);
cout<<ans<<endl;
}
return 0;
}