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 ...
随机推荐
- Android 之 Eclipse 导入 Android 源码
很多人都下载过下图中的 Sources for Android SDK,但是很少人知道怎么用 下载完毕后可以再 Android SDK 根目录下看到 sources 文件夹内 有 andr ...
- Linux usb子系统(三):通过usbfs操作设备的用户空间驱动
内核中提供了USB设备文件系统(usbdevfs,Linux 2.6改为usbfs,即USB文件系统),它和/proc类似,都是动态产生的.通过在/etc/fstab文件中添加如下一行:none /p ...
- 禁用UITableViewCell 重用机制
有时候不想让Cell重用,怎么办勒.接下来介绍两种方法 方法一 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAt ...
- [j2ee][IDEA properties中文乱码解决]
http://my.oschina.net/pengzai/blog/133908 在project settings - File Encoding,在标红的选项上打上勾,确定即可
- MBTI性格测试
INFP 哲学家型——生活在自己的理想世界 报告接收人: 才储成员4361454 日期: 2014/9/2 一.你的MBTI图形 倾向示意图表示四个维度分别的倾向程度.从中间往两侧看,绿色指示条对应下 ...
- Mysql 复制表结构 及其表的内容
顺便转一下Mysql复制表结构.表数据的方法: 1.复制表结构及数据到新表CREATE TABLE 新表 SELECT * FROM 旧表 这种方法会将oldtable中所有的内容都拷贝过来,当然我们 ...
- volley三种基本请求图片的方式与Lru的基本使用:正常的加载+含有Lru缓存的加载+Volley控件networkImageview的使用
首先做出全局的请求队列 package com.qg.lizhanqi.myvolleydemo; import android.app.Application; import com.android ...
- JS截取字符串:slice(),substring()和substr()
var string='abcdefg' 1.slice() string.slice(startLocation [, endLocation]) ps1:2个参数可以为负数,若参数值为负数,则将该 ...
- node.js如何使用回调
Node.js到处使用回调,尤其在有I/O(输入/输出)操作的地方. 下面是在一个Node.js中使用filesystem模块中从磁盘上读入文件内容示例一: var fs = require('fs' ...
- Java中的事务——JDBC事务和JTA事务
Java中的事务——JDBC事务和JTA事务 转载:http://www.hollischuang.com/archives/1658 之前的事务介绍基本都是数据库层面的事务,本文来介绍一下J2EE中 ...