Clarke and points
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 106 Accepted Submission(s): 80
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
题意:给你n个二维平面的点,求两点间最大曼哈顿距离。
思路:化简|x1 - x2| + |y1 - y2|就出来了。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF (2000000000+10)
#define eps 1e-8
#define MAXN (300000+10)
#define MAXM (600000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while((a)--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
#pragma comment(linker, "/STACK:102400000,102400000")
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
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; Ri(t);
W(t)
{
int n; Ri(n); scanf("%I64d", &seed);
LL Max1 = -INF, Max2 = -INF, Min1 = INF, Min2 = INF;
for(int i = 0; i < n; i++)
{
LL x, y;
x = rand(-1000000000, 1000000000);
y = rand(-1000000000, 1000000000);
Max1 = max(Max1, x + y);
Min1 = min(Min1, x + y);
Max2 = max(Max2, x - y);
Min2 = min(Min2, x - y);
}
cout << max(Max1 - Min1, Max2 - Min2) << endl;
}
return 0;
}