hdu 5626 Clarke and points
``` 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); ```
3 233
5 332
1423870062
先附上自己的写法,运气好的话可以过,运气不好的话超时,这东西也看人品?
#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的更多相关文章
- HDU 5626 Clarke and points 平面两点曼哈顿最远距离
Clarke and points 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5626 Description Clarke is a patie ...
- hdu 5626 Clarke and points 数学推理
Clarke and points Problem Description The Manhattan Distance between point A(XA,YA) and B(XB,YB) i ...
- 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 5565 Clarke and baton 二分
Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 5464 Clarke and problem dp
Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
- hdu 5627 Clarke and MST(最大 生成树)
Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...
- HDU 5628 Clarke and math dp+数学
Clarke and math 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5628 Description Clarke is a patient ...
随机推荐
- MySQL 索引优化全攻略
所谓索引就是为特定的mysql字段进行一些特定的算法排序,比如二叉树的算法和哈希算法,哈希算法是通过建立特征值,然后根据特征值来快速查找.而用的最多,并且是mysql默认的就是二叉树算法 BTREE, ...
- sqlserver练习
1.基本表的练习: create table Test( name ), age int, sex ) ) alter table Test ) alter table Test ) alter ta ...
- Rhythmbox中文乱码解决的方法
转自:http://hi.baidu.com/morgensonne/item/3470aef58747abde6325d2d9 今天在网络上找到了一个比較好的解决Rhythmbox中文乱码的问题的方 ...
- Coreseek:常见的问题2
1.failed to lock XXXXX.spl档 这是当你构建的指数将是一个问题,您不必打开searchd服务关闭,既然你开searchd维修,他将建立呼叫xxx.spl临时文件,施工时的指数会 ...
- 连载:面向对象葵花宝典:思想、技巧与实践(33) - ISP原则
ISP,Interface Segregation Principle,中文翻译为"接口隔离原则". 和DIP原则一样,ISP原则也是大名鼎鼎的Martin大师提出来的,他在19 ...
- Android内存泄漏监测(MAT)及解决办法
http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html 这篇文章是2010年1月份写的,其中有些已经 ...
- 涂抹Oracle笔记1-创建数据库及配置监听程序
一.安装ORACLE数据库软件及创建实例OLTP:online transaction processing 指那些短事务,高并发,读写频繁的数据库系统.--DB_BLOCK_SIZE通常设置较小.O ...
- 1203.2——条件语句 之 switch语句
用 if else 语句在处理多分支的时候,分支太多就会显得不方便,且容易出现 if 和 else配对出现错误的情况.例如,输入一个整数,输出该整数对应的星期几的英文表示: #include < ...
- codeforces 337D Book of Evil(dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Book of Evil Paladin Manao caught the tra ...
- git merge的recursive策略和merge-base
git的合并策略总共有3种,一种是resovle,一种是recursive,一种是octopus.其中resolve和recursive适用于合并2个branch,octopus适用于合并3个或者3个 ...