Clarke and points

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5626

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.

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);

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

Hint

题意

让你求平面两点的曼哈顿最远距离

题解:

显然我们可以看出距离 = abs(x1-x2)+abs(y1-y2)

我们把绝对值拆开,然后再归纳一下,显然可以分为一下四种情况(x1+y1)-(x2+y2),(x1-y1)-(x2-y2),(-x1+y1)-(-x2+y2),(-x1-y1)-(-x2-y2)

我们可以看出减号左右是相同的,所以我们维护这四个值的最大最小值就好了

代码

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1e6+7;
int 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);
}
long long Max[10];
long long Min[10];
int main()
{
int t;
scanf("%d",&t);
for(int cas=1;cas<=t;cas++)
{
cin >> n >> seed;
for(int i=0;i<10;i++)
Max[i]=-1e15,Min[i]=1e15;
long long x,y;
for (int i = 0; i < n; i++)
{
x = rand(-1000000000, 1000000000),
y = rand(-1000000000, 1000000000);
Max[0]=max(Max[0],x+y);
Max[1]=max(Max[1],-x+y);
Max[2]=max(Max[2],x-y);
Max[3]=max(Max[3],-x-y);
Min[0]=min(Min[0],x+y);
Min[1]=min(Min[1],-x+y);
Min[2]=min(Min[2],x-y);
Min[3]=min(Min[3],-x-y);
}
long long ans = 0;
for(int i=0;i<4;i++)
ans=max(Max[i]-Min[i],ans);
cout<<ans<<endl;
}
}

HDU 5626 Clarke and points 平面两点曼哈顿最远距离的更多相关文章

  1. hdu 5626 Clarke and points 数学推理

    Clarke and points Problem Description   The Manhattan Distance between point A(XA,YA) and B(XB,YB) i ...

  2. hdu 5626 Clarke and points

    Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...

  3. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  4. hdu 5563 Clarke and five-pointed star 水题

    Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...

  5. HDU 2376 树形dp|树上任意两点距离和的平均值

    原题:http://acm.hdu.edu.cn/showproblem.php?pid=2376 经典问题,求的是树上任意两点和的平均值. 这里我们不能枚举点,这样n^2的复杂度.我们可以枚举每一条 ...

  6. HDU 4717 The Moving Points(三分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...

  7. hdu 5565 Clarke and baton 二分

    Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. hdu 4717 The Moving Points(第一个三分题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...

  9. hdu 5465 Clarke and puzzle 二维线段树

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

随机推荐

  1. vue路由-动态路由和嵌套路由

    一.动态路由 我们经常需要把某种模式匹配到的所有路由,全都映射到同个组件.例如,我们有一个 User 组件,对于所有 ID 各不相同的用户,都要使用这个组件来渲染.那么,我们可以在 vue-route ...

  2. C++学习之路(七):以const,enum,inline替换#define

    这篇博文主要是编程中的一些问题和技巧.如题目所示,这些关键字的作用不再进行描述.直接描述功能和实例代码. 首先,在头文件中对类进行定义,是不会为类分配内存空间的,在这一点上类定义可以和普通变量类型的声 ...

  3. Jmeter跨线程组传递变量

    请求API需要授权令牌,但是授权令牌只需要获取一次,即可调用服务器上其他业务接口. 所以我想要把授权操作放在单独的一个线程,业务流放在其他线程. 这就需要我把从授权线程获取的令牌传入业务流线程. 解决 ...

  4. .net爬虫了解一下

    using System; //添加selenium的引用 using OpenQA.Selenium.PhantomJS; using OpenQA.Selenium.Chrome; using O ...

  5. 文件上传实现ajax假异步

    $.ajaxFileUpload({ url : getSitePath()+'/jlyElderly/doUpdateImage', secureuri : false,//是否需要安全协议 fil ...

  6. JavaScript中对象的属性类型

    JavaScript中,对象的属性有两种:数据属性和访问器属性. 数据属性 特性: 数据属性包括一个数据值的位置.在这个位置可以读取和写入值.数据属性有4个特性. [[configurable]]:可 ...

  7. django开发项目实例2--如何链接图片和css文件(静态文件)

    在上一篇随笔里面,我们已经介绍了如何从零开始用django建立一个项目并且初步运行以来了, 现在我们就要开始写我们的html了,也就是django里面的模板了,不过这节我们只讲如何链接图片和css(静 ...

  8. SEO优化:WordPress站点地图(html和xml)插件Baidu Sitemap Generator

    前阵子分享了<如何实现纯代码制作网站地图的html和xml版本>,不过不是每个人都喜欢用纯代码来折腾博客的.今天,boke112就给大家分享一款国人柳城制作的包含html和xml两个版本的 ...

  9. vue利用watch侦听对象具体的属性 ~ 巧用计算属性computed做中间层

    有时候需要侦听某个对象具体的属性,可以按下面案例进行: <template> <div> <input type="text" v-model=&qu ...

  10. 使用 gulp 构建一个项目

    本章将介绍 gulp-watch-path stream-combiner2 gulp-sourcemaps gulp-autoprefixer 您还可以直接学习以下模块: 安装 Node 和 gul ...