HDU 5626 Clarke and points
2016-02-18 12:18
232 查看
问题描述
输入描述
输出描述
输入样例
输出样例
克拉克是一名精神分裂患者。某一天克拉克变成了一位几何研究学者。 他研究一个有趣的距离,曼哈顿距离。点A(x_A, y_A)A(xA,yA)和点B(x_B, y_B)B(xB,yB)的曼哈顿距离为|x_A-x_B|+|y_A-y_B|∣xA−xB∣+∣yA−yB∣。 现在他有nn个这样的点,他需要找出两个点i, ji,j使得曼哈顿距离最大。
输入描述
第一行是一个整数T(1 \le T \le 5)T(1≤T≤5),表示数据组数。 每组数据第一行为两个整数n, seed(2 \le n \le 1000000, 1 \le seed \le 10^9)n,seed(2≤n≤1000000,1≤seed≤109),表示点的个数和种子。 nn个点的坐标是这样得到的: 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 统计最大和最小的x+y和x-y就好了#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<iostream> #include<algorithm> #include<bitset> #include<functional> using namespace std; typedef unsigned long long ull; typedef long long LL; const int maxn = 1e6 + 10; const int mod = 1e9 + 7; int T, n; LL seed, mina, minb, maxa, maxb; struct point { LL x, y; bool operator<(const point&a)const { return x == a.x ? x < a.x : y < a.y; } }a[maxn]; inline LL 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() { scanf("%d", &T); while (T--) { cin >> n >> seed; for (int i = 0; i < n; i++) { a[i].x = rand(-1000000000, 1000000000); a[i].y = rand(-1000000000, 1000000000); } maxa = mina = a[0].x + a[0].y; maxb = minb = a[0].x - a[0].y; for (int i = 1; i < n; i++) { mina = min(mina, a[i].x + a[i].y); minb = min(minb, a[i].x - a[i].y); maxa = max(maxa, a[i].x + a[i].y); maxb = max(maxb, a[i].x - a[i].y); } cout << max(maxb - minb, maxa - mina) << endl; } return 0; }
相关文章推荐
- C#的闭包
- MySQL LEFT JOIN
- 安卓 ImageView ACTION_UP&DOWN监听
- HUST 1358 Uiwurerirexb jeqvad
- 取得编码后的HTTP字符串
- 信息指纹
- Android编程之LayoutInflater的inflate方法详解
- 信息指纹
- oracle重复数据操作
- LNK1104:无法打开文件'mfc90.lib“
- android学习参考资料
- PHP程序中 解析XML,遇到的问题
- java encapsulation
- HUST 1354 Rubiks
- android指定数据库的路径
- Linux常用命令之五:网络命令
- HUST 1353 Dartboard
- Handler(单例传值)
- .NET手记-ASP.NET MVC快速分页的实现
- 不错的链接地址