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. C#使用自定义字体(从文件获取)

    在进行软件开发,尤其是开发WinForm程序时,有时为了实现界面的美化,不可避免的需要使用一些特殊的字体,但是在开发完成之后,将程序移到其他的机器上时,由于这些机器可能没有安装相应的字体,所以整个界面 ...

  2. POJ 3114 Countries in War(强连通+最短路)

    POJ 3114 Countries in War 题目链接 题意:给定一个有向图.强连通分支内传送不须要花费,其它有一定花费.每次询问两点的最小花费 思路:强连通缩点后求最短路就可以 代码: #in ...

  3. Ubuntu12.04 Git 服务器详细配置

    Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目,学过Linux的都知道,Git的优点我就不再多说了,我也是很喜欢Linux的.今天我们一起学习Git服务器在Ubunt ...

  4. Android-------- AlertDialog中EditText无法弹出输入法的解决

    文章转自:http://21jhf.iteye.com/blog/2007375: 如果AlertDialog中有编辑录入框(newMainLayout里面动态创建了EditText控件),show后 ...

  5. Android--Toast时间

    /** * * 显示toast,自己定义显示长短. * param1:activity 传入context * param2:word 我们需要显示的toast的内容 * param3:time le ...

  6. PHP学习笔记十七【面向对象定义类】

    <?php class Person{ public $name; public $age; public function speak(){ echo "Hello world&qu ...

  7. nginx+tomcat的集群和session复制

    前端服务器采用nginx,后端应用服务器采用tomcat.nginx负责负载均衡,session复制在tomcat上处理. 1.nginx安装(略) 2.nginx配置负载均衡 http { incl ...

  8. zeromq源码分析笔记之准备(0)

    zeromq这个库主要用于进程通信,包括本地进程.网络通信,涉及到一些基础知识,主要包括管道通信,socket编程的内容,反应器模式(使用IO多路复用实现),无锁队列这几块比较重要的部分,下面的几个链 ...

  9. 已知TSP问题的最好解

    a280 : 2579ali535 : 202339att48 : 10628att532 : 27686bayg29 : 1610bays29 : 2020berlin52 : 7542bier12 ...

  10. Image的Stride

    参看下面链接:http://msdn.microsoft.com/en-us/library/aa473780