Clarke and points
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 306 Accepted Submission(s): 219
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问题描述克拉克是一名精神分裂患者。某一天克拉克变成了一位几何研究学者。 他研究一个有趣的距离,曼哈顿距离。点A(xA,yA)和点B(xB,yB)的曼哈顿距离为∣xA−xB∣+∣yA−yB∣。 现在他有n个这样的点,他需要找出两个点i,j使得曼哈顿距离最大。输入描述第一行是一个整数T(1≤T≤5),表示数据组数。 每组数据第一行为两个整数n,seed(2≤n≤1000000,1≤seed≤109),表示点的个数和种子。 n个点的坐标是这样得到的: 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);输出描述对于每组数据输出一行,表示最大的曼哈顿距离。输入样例2 3 233 5 332输出样例1557439953 1423870062//思路:这块用到一点数学的知识,就是去绝对值,总共有四种情况(应该都知道),但列出来之后会发现可以合并成两种情况。情况一:(Xa+Ya)-(Xb+Yb);情况二:(Xa-Ya)-(Xb-Yb);所以只用求出这两种情况的最大值即为所求。。#include<stdio.h> #include<string.h> #include<algorithm> #define INF 0x3f3f3f3f #define ll long long #define N 1000010 using namespace std; 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); } int main() { int t,n,i; scanf("%d",&t); while(t--) { scanf("%d%lld",&n,&seed); ll x1=-INF,x2=-INF; ll y1=INF,y2=INF; for (i = 0; i < n; i++) { ll x,y; x = rand(-1000000000, 1000000000); y = rand(-1000000000, 1000000000); x1=max(x1,x+y);x2=max(x2,x-y); y1=min(y1,x+y);y2=min(y2,x-y); } ll sum=max(x1-y1,x2-y2); printf("%lld\n",sum); } return 0; }