Clarke and points
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 480 Accepted Submission(s): 337
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<iostream>
using namespace std;
typedef long long ll;
ll seed;
inline ll rand(ll l, ll r){
static ll mo=1e9+7,g=78125;
return l+((seed*=g)%=mo)%(r-l+1);
}
ll ldj(ll n){
if(n<0) return -n;
else return n;
}
int main(){
int test;
cin>>test;
while(test--){
int n;
cin>>n>>seed;
ll x,y;
ll maxx=-0x3f3f3f3f,maxy=-0x3f3f3f3f;
ll minx=0x3f3f3f3f,miny=0x3f3f3f3f;
for(int i=0;i<n;i++){
x=rand(-1000000000,1000000000);
y=rand(-1000000000,1000000000);
maxx=max(maxx,x+y);
maxy=max(maxy,x-y);
minx=min(minx,x+y);
miny=min(miny,x-y);
}
cout<<max((maxx-minx),(maxy-miny))<<endl;
}
}