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 |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
 
Source
 

先附上自己的写法,运气好的话可以过,运气不好的话超时,这东西也看人品?

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000006
#define inf 1e12 struct node{
ll x,y;
}e[N],res[N];
ll cmp(node a,node b)
{
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
ll cross(node a,node b,node c)//向量积
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
ll convex(ll n)//求凸包上的点
{
sort(e,e+n,cmp);
ll m=,i,j,k;
//求得下凸包,逆时针
//已知凸包点m个,如果新加入点为i,则向量(m-2,i)必定要在(m-2,m-1)的逆时针方向才符合凸包的性质
//若不成立,则m-1点不在凸包上。
for(i=;i<n;i++)
{
while(m>&&cross(res[m-],e[i],res[m-])<=)m--;
res[m++]=e[i];
}
k=m;
//求得上凸包
for(i=n-;i>=;i--)
{
while(m>k&&cross(res[m-],e[i],res[m-])<=)m--;
res[m++]=e[i];
}
if(n>)m--;//起始点重复。
return m;
} long long n,seed;
inline long long rand(long long l, long long r) {
static long long mo=1e9+, g=;
return l+((seed*=g)%=mo)%(r-l+);
} int main()
{
int t;
scanf("%d",&t);
while(t--){
cin >> n >> seed;
for (int i = ; i < n; i++){
e[i].x = rand(-, ),
e[i].y = rand(-, );
}
ll m=convex(n);
ll ans=-;
for(ll i=;i<m;i++){
for(ll j=i+;j<m;j++){
ll cnt = abs(res[i].x-res[j].x)+abs(res[i].y-res[j].y);
ans=max(ans,cnt);
}
}
printf("%I64d\n",ans); }
return ;
}

官方题解:

 #include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii; inline int in()
{
int res=;char c;int f=;
while((c=getchar())<'' || c>'')if(c=='-')f=-;
while(c>='' && c<='')res=res*+c-'',c=getchar();
return res*f;
}
const int N = ; ll a[N][];
int n;
long long seed;
inline long long rand(long long l, long long r) {
static long long mo=1e9+, g=;
return l+((seed*=g)%=mo)%(r-l+);
}
int main() {
int T;
for (scanf("%d", &T);T--;) {
cin >> n >> seed;
for (int i=; i<n; i++)
a[i][]=rand(-, ),
a[i][]=rand(-, );
ll t=;
ll ans=,mx=-9223372036854775808LL,mn=9223372036854775807LL;
for (int s=; s<(<<); s++) {
mx=-9223372036854775808LL,mn=9223372036854775807LL;
for (int i=; i<n; i++) {
t = ;
for (int j=; j<; j++)
if ((<<j) & s) t += a[i][j];
else t -= a[i][j];
mn = min(mn, t);
mx = max(mx, t);
}
ans = max(ans, mx-mn);
}
printf("%I64d\n", ans);
}
return ;
}

hdu 5626 Clarke and points的更多相关文章

  1. HDU 5626 Clarke and points 平面两点曼哈顿最远距离

    Clarke and points 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5626 Description Clarke is a patie ...

  2. hdu 5626 Clarke and points 数学推理

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

  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 5565 Clarke and baton 二分

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

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

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

  7. hdu 5464 Clarke and problem dp

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

  8. hdu 5627 Clarke and MST(最大 生成树)

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

  9. HDU 5628 Clarke and math dp+数学

    Clarke and math 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5628 Description Clarke is a patient ...

随机推荐

  1. 脚本控制向Android模拟拨打电话,发送短信,定位设置功能

    做行为触发的时候要向模拟器实现拨打电话,发送短信,定位设置的的功能,可以很方便通过telnet localhost  5554实现. 写个脚本很快的搞定了.网上资料很多,脚本的很少,也所积点德啦. 写 ...

  2. hdu 5656 CA Loves GCD(dp)

    题目的意思就是: n个数,求n个数所有子集的最大公约数之和. 第一种方法: 枚举子集,求每一种子集的gcd之和,n=1000,复杂度O(2^n). 谁去用? 所以只能优化! 题目中有很重要的一句话! ...

  3. Android恢复出厂设置流程分析【Android源码解析十】

    最近看恢复出厂的一个问题,以前也查过这方面的流程,所以这里整理一些AP+framework层的流程: 在setting-->备份与重置--->恢复出厂设置--->重置手机---> ...

  4. POJ训练计划2777_Count Color(线段树/成段更新/区间染色)

    解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...

  5. rz/sz上传下载

    z(Zmodem文件传输协议) rz  文件上传(Receive Zmodem)  rz sz  文件下载(Send Zmodem)  sz filename rz/sz工具需要自己安装

  6. fuser:用文件或者套接口表示进程

    fuser:用文件或者套接口表示进程 作用:fuser命令用文件或者套接口表示进程. 用法:fuser [-a | -s | -c] [-4 | -6] [-n space] [-k [-i] [-s ...

  7. 关于Http协议(2)--转载

    原文链接:http://www.cnblogs.com/mcad/ HTTP工作原理图 请求报文 1.请求报文长什么样?  Chrome核心的请求报文 2.报文结构 3.报文头部每个字段的意义 //从 ...

  8. overflow清楚浮动 + 去掉li标签的小圆点

    原文链接:http://blog.163.com/qqabc20082006@126/blog/static/22928525201031211212955/ 测试用例: <!DOCTYPE h ...

  9. Chrome 开发者工具详解(4):Profiles 面板

    概述 当前使用的Chrome最新版为54.0.2840.71,这个版本的Profiles面板比之前提供的功能更多也更强大,下面是该面板所包含的功能点: Record JavaScript CPU Pr ...

  10. PHP学习笔记三十五【Try】

    <?php function AddUser($name) { if($name=="张三") { echo "add success"; return ...