cf 424
Office Keys
首先显然有随人位置的递增,钥匙的位置也要递增,这样考虑两张做法:
1.$f(i,j)$ 表示前i个人,钥匙到第j个最少用的最大时间,然后$O(nK)$ dp
2.二分时间,对于每一个人选择当前能选择的最左面的钥匙 $O((n+K) logn)$
#include <bits/stdc++.h> #define LL long long const int N = ; using namespace std; int n,m,pre[N],a[N],b[N]; int Abs(int x)
{
if(x<) return -x;
return x;
} int p; bool check(int tim)
{
int j = ;
for(int i=;i<=n;i++)
{
while(j<=m && Abs(a[i]-b[j])+(LL)Abs(b[j]-p) > tim) j++;
if(j>m) return ;
else j++;
}
return ;
} int main()
{
int maxv = ;
scanf("%d%d%d",&n,&m,&p);
maxv = p;
for(int i=;i<=n;i++) scanf("%d",&a[i]), maxv = max(maxv ,a[i]);
for(int i=;i<=m;i++) scanf("%d",&b[i]), maxv = max(maxv, b[i]);
sort(a+,a+n+);
sort(b+,b+m+);
int l=, r=;
for(int i=;i<=n;i++) l = max(l, Abs(p-a[i]));
for(int i=;i<=n;i++) r = max(r, Abs(b[i]-a[i]) + Abs(p-b[i]));
while(r-l>)
{
int mid = (l+(LL)r)>>1LL;
if(check(mid)) r = mid;
else l = mid;
}
for(int i=l;i<=r;i++)
if(check(i))
{
cout<<i<<endl;
break;
}
return ;
}
Cards Sorting
方法1:直接用splay模拟。
方法2:考虑每次删掉当前最小数的代价是上一个最小数和它之间的循环dist,BIT或链表即可。
(取自CF)
#include <bits/stdc++.h> const int N = ;
#define INF 0x3f3f3f3f
#define LL long long using namespace std; struct node
{
node *ch[];
int v, sum, minv;
int cmp(int x)
{
if(ch[]->sum + == x) return -;
return x > ch[]->sum;
}
node* init(int x);
void update()
{
sum = ch[]->sum + ch[]->sum + ;
minv = min(v, min(ch[]->minv, ch[]->minv));
}
}spT[N], Null, *root; int tot=; node* node::init(int x)
{
v=x;
minv=x;
ch[]=ch[]=&Null;
sum=;
return this;
} node* build(int src[],int l,int r)
{
if(l==r) return spT[++tot].init(src[l]);
int mid=(l+r)>>;
node* tmp=spT[++tot].init(src[mid]);
if(l<mid) tmp->ch[]=build(src,l,mid-);
if(mid<r) tmp->ch[]=build(src,mid+,r);
tmp->update();
return tmp;
} void rot(node* &o,int x)
{
node* tmp=o->ch[x];
o->ch[x]=tmp->ch[x^];
tmp->ch[x^]=o;
o->update();
o=tmp;
o->update();
} void splay(node* &o,int k)
{
int t=o->cmp(k);
if(t==-) return;
if(t) k-=o->ch[]->sum+;
int t1=o->ch[t]->cmp(k);
if(~t1)
{
if(t1) k-=o->ch[t]->ch[]->sum+;
splay(o->ch[t]->ch[t1],k);
if(t1==t) rot(o,t);
else rot(o->ch[t],t1);
}
rot(o,t);
} int find_min(node *&o,int minv,int now)
{
if(o->ch[]->minv == minv) return find_min(o->ch[],minv,now);
else
{
if(o->v == minv) return now+o->ch[]->sum;
return find_min(o->ch[],minv,now+o->ch[]->sum+);
}
} int n,a[N]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
Null.minv = INF;
a[]=INF;
a[n+]=INF;
root = build(a,,n+);
int len = n+;
LL ans = ;
for(int i=;i<=n;i++)
{
int tmp = find_min(root,root->minv,);
ans += (LL)tmp;
splay(root,);
splay(root->ch[],tmp+);
node* tp = root->ch[]->ch[];
root->ch[]->ch[] = &Null;
root->ch[]->update();
root->update(); splay(tp,tp->sum);
tp = tp->ch[];
len--; splay(root,len-tp->sum);
splay(root->ch[],len-tp->sum-);
root->ch[]->ch[] = tp;
root->ch[]->update();
root->update();
}
cout << ans << endl;
return ;
}
Bamboo Partition
显然要满足的条件等价于
$\sum_{i=1}^n { [\frac{a_i + d - 1}{d}] \cdot d - a_i} \leq K$
$F(d) = \sum_{i=1}^n { [\frac{a_i - 1}{d}] + 1} \cdot d \leq K + \sum {a_i}$
固定 $\sum_{i=1}^n { [\frac{a_i - 1}{d}] + 1}$,从而 $F(d)$ 单调。
对于前者直接找出所有得数相同的 $d$ 的区间,逐一计算即可。
复杂度$O(n^2 \sqrt {a_i} )$
通过调参可以 $O(n \sqrt {a_{max} n})$
#include <bits/stdc++.h> #define LL long long const int N = ; using namespace std; int n,tot,a[N];
LL K;
vector<int> v; int main()
{
cin>>n>>K;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
K += (LL)a[i];
int j=;
int tmp = a[i]-;
if(tmp>)
{
for(int i=;i<=tmp;i=j+)
j = tmp/(tmp/i), v.push_back(i);
v.push_back(tmp+);
}
}
v.push_back();
sort(v.begin(),v.end());
v.resize(distance(v.begin(), unique(v.begin(), v.end())));
LL ans = , sum;
for(int i=;i<(int)v.size() - ;i++)
{
int l = v[i], r = v[i+]-;
sum = ;
for(int j=;j<=n;j++) sum += (a[j]-1LL)/l + 1LL;
LL tmp = min(K/sum, (LL)r);
if(tmp>=l) ans = tmp;
}
LL l = v[v.size()-];
LL tmp = K/n;
if(tmp >= l) ans = tmp;
cout << ans << endl;
}
cf 424的更多相关文章
- CF Round #424 Div.2 D
n个人拿K个钥匙中的n个然后到办公室(点p) 问最少需要的时间是多少 先排序 如果j<=i 则必须拿这个钥匙 dp[i][j]=max(dp[i-1][j-1],abs(p-b[j])+abs( ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
随机推荐
- window 平台搭建简单的直播点播系统
Windows平台如何搭建简单的直播系统前文已经有介绍,今天介绍下如何搭建简单的点播系统. 同样还是利用crtmpServer,crtmpServer可以从github中下载,可以从群里下载(群里有修 ...
- AtomicInteger在实际项目中的应用
AtomicInteger.一个提供原子操作的Integer的类. 在Java语言中,++i和i++操作并非线程安全的.在使用的时候,不可避免的会用到synchronized关键字. 而AtomicI ...
- 从主机给VM Copy文件
不能从主机给VM 复制文件,在VM里,setting --->option--->shareFolder-->enable-->add(要share的文件路径) then=== ...
- generate alphanumeric serial number
generate alphanumeric serial number with the following BADI / Customer Exit: Name of Enhancement : I ...
- vue directive demo
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- struts2上传图片超过大小给出错误提示
struts2上传图片超过大小给出错误提示 今天碰到上传图片太大,上传不上去返回input视图的界面,回显的错误信息却是乱码,整了好久才整出来,在这里做个记录,方便自己以后查阅,也希望能 ...
- TCP 同步传输:客户端发送,服务器段接收
1.服务器端程序 可以在TcpClient上调用GetStream()方法来获的链接到远程计算机的网络流NetworkStream.当在客户端调用时,他获的链接服务器端的流:当在服务器端调用时,他获得 ...
- LeetCode(155)题解--Min Stack
https://leetcode.com/problems/min-stack/ 题目: Design a stack that supports push, pop, top, and retrie ...
- Darwin Streaming Server性能测试报告
为了验证Darwin Streaming Server在流媒体点播上的性能,EasyDarwin开源项目官方特地与国内某大型视频网站进行了一次性能测试(千兆网络环境下),针对本次RTSP直播流媒体测试 ...
- Linux常用命令——持续更新(2018-05-09)
此命令默认是在centos环境下执行,除非特殊标明. 1.查看ip: ifconfig 2.创建指定用户并分配到某个组:创建用户user并分配到root组 useradd -g root user 3 ...