bestcoder #72Clarke and points

Clarke and points

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 146    Accepted Submission(s): 108


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  |xAxB|+|yAyB|
Now he wants to find the maximum distance between two points of  n  points.
 

Input
The first line contains a integer  T(1T5) , the number of test case. 
For each test case, a line followed, contains two integers  n,seed(2n1000000,1seed109) , 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
 

题目大意:

       求 |xAxB|+|yAyB| . 的最大值。分类xa > xb, xa < xb ,ya > yb, ya < yb讨论一下,然后看到其实只是max((xA+yA)(xB+yB),(xAyA)(xByB))


。。。这种水题竟然在当时,唉。不说了




#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<stack> #include<map> using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; const ll maxn = 1000000 + 50; ll x[maxn], y[maxn], n, seed; inline long long rand(long long l, long long r) { static long long mo = 1000000000 + 7, g = 78125; return l + ((seed *= g) %= mo) % (r - l + 1); } void solve(){ scanf("%I64d%I64d", &n, &seed); x[0] = rand(-1000000000, 1000000000); y[0] = rand(-1000000000, 1000000000); ll tmx1 = x[0] - y[0], tmx2 = x[0] + y[0]; ll tmx3 = x[0] - y[0], tmx4 = x[0] + y[0]; for (int i = 1; i < n; i++){ x[i] = rand(-1000000000, 1000000000), y[i] = rand(-1000000000, 1000000000); tmx1 = max(tmx1, x[i] - y[i]); tmx3 = min(tmx3, x[i] - y[i]); tmx2 = max(tmx2, x[i] + y[i]); tmx4 = min(tmx4, x[i] + y[i]); } ll tmp = max(abs(tmx1 - tmx3), abs(tmx2 - tmx4)); printf("%I64d\n", tmp); } int main(){ int t; scanf("%d", &t); while (t--){ solve(); } return 0; } </map></stack></queue></cmath></cstring></algorithm></cstdio>
|xAxB|+|yAyB|
|xAxB|+|yAyB|

你可能感兴趣的:(bestcoder #72Clarke and points)