HDU 5626 Clarke and points 平面两点曼哈顿最远距离
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 平面两点曼哈顿最远距离的更多相关文章
- hdu 5626 Clarke and points 数学推理
Clarke and points Problem Description The Manhattan Distance between point A(XA,YA) and B(XB,YB) i ...
- hdu 5626 Clarke and points
Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- 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 ...
- HDU 2376 树形dp|树上任意两点距离和的平均值
原题:http://acm.hdu.edu.cn/showproblem.php?pid=2376 经典问题,求的是树上任意两点和的平均值. 这里我们不能枚举点,这样n^2的复杂度.我们可以枚举每一条 ...
- HDU 4717 The Moving Points(三分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...
- hdu 5565 Clarke and baton 二分
Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 4717 The Moving Points(第一个三分题)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
随机推荐
- 网络设备之分配net_device结构
注册网络设备时,会调用pci_driver->probe函数,以e100为例,最终会调用alloc_netdev_mqs来分配内存,并且在分配内存后调用setup函数(以太网为ether_set ...
- elasticsearch批量删除(查询删除)
注:delete by query只适用于低于elasticsearch2.0的版本(不包含2.0).有两种形式: 1.无请求体 curl -XDELETE 'localhost:9200/twitt ...
- Asp.net 模板下载和导入到DataTable中
HTML页面: <tr> <td colspan=" style="text-align: left; border: 1px;"> <as ...
- PHP PDO类
<?php //数据库连接类,不建议直接使用DB,而是对DB封装一层 //这个类不会被污染,不会被直接调用 class DB { //pdo对象 private $_pdo = null; // ...
- windows 安装tp5 composer方式
1.下载windows composer-setup.exe(我已下载一个Composer-Setup.exe); 2.我电脑使用的是phpstudy2018版 php-7.0.12-NTS 3.然后 ...
- [onethink ucenter] 跨域名单点登录关键点
1.uc_client/data/cache/apps.php <?php $_CACHE['apps'] = array ( 1 => array ( 'appid' => '1' ...
- 第八届山东省ACM大学生程序设计竞赛个人总结
因为省赛,从开学紧张到5月7号.心思也几乎全放在ACM的训练上.因为我还是校台球协会的会长,所以台协还有一些事情需要忙,但是我都给延迟了.老会长一直在催我办校赛,但我一直说 等等吧,因为校赛只能在周六 ...
- CSS中包含块原理解析
CSS包含块原理解析 确定CSS中的包含块也确定就是元素的父元素.关键是:看元素是如何定位的.确定包含块很重要,比如设置百分比.另外也可以进行样式的继承等等. 分两个情况: 相对定位和静态定位 静态定 ...
- 设计模式-组合模式(Composite Pattern)
本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ 前置技能:认识数据结构中的树形结构. 组合模式简介 组合模式是将对象组合成树形结构以表示“部分- ...
- 解决Xamarin Android SDK Manager闪退问题
解决Xamarin Android SDK Manager闪退问题 SDK Manager闪退是因为它找不到java.exe导致的.SDK Manager默认是通过读取注册表中JDK安装信息来java ...