2017.10.28 QB模拟赛 —— 下午
T1
按x值排序
遇到第二种牌插入 遇到第一种牌 查询<=y 的最小值 删除他
splay multiset
cys大佬说 multiset就是不去重的set,
#include <algorithm>
#include <cstdio>
#define N 100005
using namespace std;
struct node
{
int x,y,opt;
bool operator<(node a)const
{
if(opt!=a.opt&&x==a.x) return opt>a.opt;
else return x<a.x;
}
}card[N<<];
];
inline void pushup(int rt)
{
],r=ch[rt][];
siz[rt]=siz[l]+siz[r]+cnt[rt];
}
inline void ins(int &rt,int x)
{
if(!rt)
{
rt=++cn;
data[cn]=x;
siz[cn]=cnt[cn]=;
return;
}
if(data[rt]==x)
{
cnt[rt]++;
siz[rt]++;
return;
}
if(x<data[rt])
{
ins(ch[rt][],x);
fa[ch[rt][]]=rt;
pushup(rt);
}
else
{
ins(ch[rt][],x);
fa[ch[rt][]]=rt;
pushup(rt);
}
}
int ask_pre(int rt,int x)
{
int p=rt,ret=0x7fffffff;
while(p)
{
];
else
{
ret=data[p];
p=ch[p][];
}
}
return ret;
}
inline ]==x;}
void rotate(int x)
{
int y=fa[x],z=fa[y],b=son(x),c=son(y),a=ch[x][!b];
if(z) ch[z][c]=x;
else root=x;
fa[x]=z;
if(a) fa[a]=y;
ch[x][!b]=y;ch[y][b]=a;
fa[y]=x;
pushup(y);pushup(x);
}
void splay(int x,int i)
{
while(fa[x]!=i)
{
int y=fa[x],z=fa[y];
if(z==i) rotate(x);
else
{
if(son(y)==son(x)) rotate(y),rotate(x);
else rotate(x),rotate(x);
}
}
}
int getmn(int rt)
{
,p=rt;
while(p)
{
ret=p;
p=ch[p][];
}
return ret;
}
void del(int rt,int x)
{
if(data[rt]==x)
{
)
{
cnt[rt]--;
siz[rt]--;
}
else
{
splay(rt,);
]);
)
{
splay(p,rt);
root=p;fa[p]=;
ch[p][]=ch[rt][];
fa[ch[rt][]]=p;
}
else
{
root=ch[rt][];
fa[ch[rt][]]=;
}
}
return;
}
if(x<data[rt])
{
del(ch[rt][],x);
pushup(rt);
}
else
{
del(ch[rt][],x);
pushup(rt);
}
}
int main(int argc,char *argv[])
{
freopen("water.in","r",stdin);
freopen("water.out","w",stdout);
scanf("%d",&n);
;i<=n;++i) scanf(;
;i<=n<<;++i) scanf(;
sort(card+,card++n*);
;i<=n<<;++i)
{
) ins(root,card[i].y);
else
{
if(!cn) continue;
int v=ask_pre(root,card[i].y);
if(v==0x7fffffff) continue;
ans++;
del(root,v);
}
}
printf("%d\n",ans);
fclose(stdin); fclose(stdout);
;
}
splay
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int n;
multiset <int> s;
],b[];
int cmp(node i,node j) {return i.x<j.x;}
int main()
{
freopen("water.in","r",stdin);
freopen("water.out","w",stdout);
int T;
T=;
while(T--)
{
scanf("%d",&n);
;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y);
;i<n;i++) scanf("%d%d",&b[i].x,&b[i].y);
sort(a,a+n,cmp);
sort(b,b+n,cmp);
s.clear();
,ans=;
;i<n;i++)
{
while(a[i].x>=b[k].x&&k<n)
{
s.insert(b[k].y);
k++;
}
if(s.empty())continue;
multiset<int>::iterator it=s.upper_bound(a[i].y);
if (it==s.begin()) continue; it--;
ans++; s.erase(it);
}
printf("%d\n",ans);
}
;
}
multiset
T2
最少需要 log(n)/log(2) 个
dp[j][k] 表示 金币和是 j 最大金币是k 的方案总数
枚举下一枚金币是什么
#include <cstdio>
#include <cmath>
#define N 1005
inline int min(int a,int b) {return a>b?b:a;}
int n,s,ans,f[N][N],dp[N][N];
int main(int argc,char *argv[])
{
freopen("dream.in","r",stdin);
freopen("dream.out","w",stdout);
scanf("%d",&n);
s=log2(n)+;
f[][]=;
;i<s;++i)
{
;j<=n;++j)
;k<=n;++k)
if(f[j][k])
;l<=j+;++l)
dp[min(n,j+l)][l]+=f[j][k];
;j<=n;++j)
;k<=n;++k)
f[j][k]=dp[j][k],dp[j][k]=;
}
;i<=n;++i) ans+=f[n][i];
printf("%d %d\n",s,ans);
fclose(stdin);
fclose(stdout);
;
}
T3
dp[i][j] 表示 1~i 切了j刀的最优解
dp[i][j]=min{dp[k][j-1]+sum(k+1,i)}
从大到小 枚举k 更新sum
复杂度 20*N^2
固定j,随着i的增大,k不会减少
1d1d动态规划优化
20*n^2的简单dp -> 在固定j的情况下 随着i的增大,k不降 -> 分治求dp值
#include <cstdio>
#define N 100005
typedef long long LL;
int n,k,L,R,a[N],s[N];
LL sum,f[N],g[N];
void update(int x,int type)
{
) sum+=s[a[x]],++s[a[x]];
else --s[a[x]],sum-=s[a[x]];
}
void move(int l,int r)
{
);
);
);
);
}
void work(int l,int r,int fl,int fr)
{
if(fl>fr) return;
,mi;
LL mx=1LL<<;
for(int i=l;i<mid&&i<=r;++i)
{
move(i+,mid);
if(mx>f[i]+sum) mx=f[i]+sum,mi=i;
}
g[mid]=mx;
work(l,mi,fl,mid-);
work(mi,r,mid+,fr);
}
int main(int argc,char *argv[])
{
freopen("dp.in","r",stdin);
freopen("dp.out","w",stdout);
scanf("%d%d",&n,&k);
;i<=n;++i) scanf("%d",&a[i]);
f[]=;
;i<=n;++i) f[i]=1LL<<;
while(k--)
{
L=,R=,sum=;
;i<=n;++i) s[i]=;
work(,n-,,n);
;i<=n;++i) f[i]=g[i],g[i]=;
}
printf("%I64d\n",f[n]);
fclose(stdin); fclose(stdout);
;
}
2017.10.28 QB模拟赛 —— 下午的更多相关文章
- 2017.10.28 QB模拟赛 —— 上午
题目链接 T1 1e18 内的立方数有 1e6个 直接枚举可过 二分最优 考场用set 死慢.. #include <cstdio> int t; long long p; int ma ...
- 2017 10.25 NOIP模拟赛
期望得分:100+40+100=240 实际得分:50+40+20=110 T1 start取了min没有用,w(゚Д゚)w O(≧口≦)O T3 代码3个bug :数组开小了,一个细节没注意, ...
- 2017.10.7 QBXT 模拟赛
题目链接 T1 容斥原理,根据奇偶性进行加减 #include<iostream> #include<cstdio> using namespace std; typedef ...
- 2017.10.3 QBXT 模拟赛
题目链接 T1 模拟 #include <cstring> #include <cstdio> #define N 105000 int L,R; char s[N]; int ...
- 2017.10.6 QBXT 模拟赛
题目链接 T1 Sort 一下与原数组比较 ,若有两个数或者没有数发生位置交换 ,则输出YES ,否则输出NO #include <algorithm> #include <ccty ...
- 2017.10.5 QBXT 模拟赛
题目链接 T1 从小到大排序,用sum记录前缀和,然后枚举1~n个数 ,如果当前的前缀和 + 1小于a[i]的话 那么 sum + 1永远不可能拼出来 直接输出sum + 1 ,否则统计前缀和.最后如 ...
- 2017.10.4 QBXT 模拟赛
题目链接 T1 维护一个单调栈 #include <iostream> #include <cstdio> #define N 500000 #define rep(a,b,c ...
- 2017.10.2 QBXT 模拟赛
题目链接 T1 我们所要求得是(a*b)|x 也就是 使(a*b)的倍数小于x的个数之和 1<=x<=n 我们可以 找一个c使得 (a*b*c)<=x 由于我们所求的是一个三元有序对 ...
- 2017.10.1 QBXT 模拟赛
题目链接 T1 枚举右端点,前缀和优化.对于当前点x,答案为 sum[x][r]-sum[x][l-1]-(sum[z][r]-sum[z][l-1]) 整理为 sum[x][r]-sum[z][r] ...
随机推荐
- Redis未授权访问反弹shell
Redis未授权访问反弹shell 目标主机:10.104.11.178 攻击机:kali 攻击步骤: 1.与目标主机连接 root@kali:~# /usr/redis/redis-cli -h 1 ...
- 1.1 Go安装与项目结构初始化
软件安装安装包下载地址为:https://golang.org/dl/ 如果打不开可以: https://golang.google.cn/dl/ https://dl.google.com/go/g ...
- Yii2 urles
public function rules(){ return [ //必须填写 ['email, username, password,agree,verifyPassword,verifyCode ...
- Silverlight 用DependencyProperty 自定义ImageButton控件 定义属性
为ImageButton自定义IconSource和Contents属性 xaml代码 <UserControl x:Class="SilverlightCreate.Silverli ...
- HDFS读写文件流程
读取: 写入:https://www.imooc.com/article/70527
- 命令行模式运行jmeter,主从方式运行jmeter
jmeter很小,很快,使用方便,可以在界面运行,可以命令行运行.简单介绍下命令行运行的方式: sh jmeter.sh -n -t my-script.jmx -R 10.6.5.31,10.6.5 ...
- Kafka Intro - Configuration
#Notes: /opt/kafka/config/zookeeper.properties sample # the directory where the snapshot is stored.d ...
- 案例49-crm练习获取客户列表带有分页和筛选功能
1 案例分析 2 书写步骤 1.封装PageBean 2.书写Action 3.书写Service 4.书写Dao 注意清空之前设置的聚合函数 dc.setProjection(null); 5 ...
- typescript的lambads解决this关键字找不到属性
var people = { name: ["abc", "jack", "pepter", "jim"], getna ...
- haproxy简单配制for mysql
1:下载haproxy 官网:http://www.haproxy.org/ 下载地址:http://www.haproxy.org/download/1.7/src/haproxy-1.7.8.ta ...