杭电hdu 5626 Clarke and points【思维】
来源:互联网 发布:网络直播足球联赛 编辑:程序博客网 时间:2024/06/07 00:28
Clarke and points
Problem Description
The Manhattan Distance between point A(XA,YA) and B(XB,YB) is |XA - XB| + |Xb - YB|;
the coordinate of each point is generated by the followed code.
Input
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);
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
我们知道曼哈顿距离的公式、当我们计算他的时候,因为有绝对值,所以我们要考虑正负值的关系,这里一共的可能有4种:
正+正、
负+负、
正+负、
负+正、
如果这里大家对官方题解的解释不是很理解,大家可以画出|x+1|+|x-2|的图像,大家对应图像就能明白了,尽量让两个值同正或者是同负的时候值会越来越大、函数图像是一眼就能看出来滴~
蓝后捏:我们对式子进行简单处理、
同正:xa-xb+ya-yb=(xa+ya)-(xb+yb)、同负的时候同理:xb-xa+yb-ya=(xa-ya)-(xb-yb)、将两个式子推出来之后,我们需要做的事情就是维护最大最小的这么几个值、
AC代码:
#include<stdio.h>#include<ctime>#include<math.h>#include<iostream>#define LL long long intusing namespace std;LL seed;inline LL rand(LL l, LL r){ static LL mo = 1e9 + 7, g = 78125; return l + ((seed *= g) %= mo) % (r - l + 1);}int main(){ int T, n; LL maxnx, maxny, minnx, minny; scanf("%d",&T); while(T--) { scanf("%d%I64d\n", &n, &seed); maxnx = maxny = -0x3f3f3f3f;//这里设定要足够大才行 minnx = minny = 0x3f3f3f3f; for(int i = 1; i <= n; ++i) { LL x = rand(-1000000000, 1000000000); LL y = rand(-1000000000, 1000000000); maxnx = max(maxnx , x + y); maxny = max(maxny , x - y); minnx = min(minnx , x + y); minny = min(minny , x - y); } printf("%I64d\n", max(maxnx - minnx, maxny - minny)); } return 0;}
0 0
- 杭电hdu 5626 Clarke and points【思维】
- HDU 5626 Clarke and points
- HDU 5626 Clarke and points
- HDU 5626 Clarke and points
- hdu 5626 Clarke and points
- hdoj 5626 Clarke and points 【思维】
- HDU Clarke and points
- HDU 5626 Clarke and points(二进制枚举)
- hdu 5626 Clarke and points 最大曼哈顿距离
- HDU 5626 Clarke and points 求平面最远哈曼顿距离
- HDU 5626 Clarke and points(最大曼哈顿距离)
- 杭电 hdu 5625 Clarke and chemistry【水题】
- hdoj 5626 Clarke and points (曼哈顿距离)
- HDU5626 Clarke and points
- HDU 5565 - Clarke and baton (思维)
- bestcoder #72Clarke and points
- 杭电5625 Clarke and chemistry
- 杭电5562之Clarke and food
- 解题报告:8VC Venture Cup 2016 — Elimination Round C.Block Towers
- Oracle学习之常用对象(四)—数据处理
- RecyclerView ---LayoutManager
- 欢迎使用CSDN-markdown编辑器
- Toolbar自定义布局
- 杭电hdu 5626 Clarke and points【思维】
- Qt For Android 引导页
- RHCE 学习笔记(21) - SELinux
- Longest Palindromic Substring
- 积跬步,聚小流------come on,我的2016
- PHP学习之Apache修改默认站点的目录
- 深度解析RARP协议
- Unity3D + ulua simpleframework的问题汇总
- 2015-2-14笔记