【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

题面

BZOJ

题解

预处理前缀后缀的结果,中间找个地方合并就好了。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
#define MAX 100100
inline int read()
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int a[MAX],b[MAX],n,tot,ans;
bool vis[MAX];
int s1[MAX],s2[MAX];
set<int> S;
int main()
{
n=read();
for(int i=1;i<=n;++i)vis[a[i]=read()]=true;
for(int i=1;i<=n+n;++i)if(!vis[i])b[++tot]=i;
for(int i=1;i<=n;++i)S.insert(b[i]);
for(int i=1;i<=n;++i)
{
set<int>::iterator it=S.upper_bound(a[i]);
if(it!=S.end())s1[i]=s1[i-1]+1,S.erase(it);
else s1[i]=s1[i-1];
}
S.clear();
for(int i=1;i<=n;++i)S.insert(-b[i]);
for(int i=n;i;--i)
{
set<int>::iterator it=S.upper_bound(-a[i]);
if(it!=S.end())s2[i]=s2[i+1]+1,S.erase(it);
else s2[i]=s2[i+1];
}
for(int i=0;i<=n;++i)ans=max(ans,s1[i]+s2[i+1]);
printf("%d\n",ans);
return 0;
}

【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)的更多相关文章

  1. 【题解】P3129高低卡(白金)High Card Low Card

    [题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规 ...

  2. [BZOJ4391][Usaco2015 dec]High Card Low Card dp+set+贪心

    Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of ...

  3. 【dp 贪心】bzoj4391: [Usaco2015 dec]High Card Low Card

    巧妙的贪心 Description Bessie the cow is a huge fan of card games, which is quite surprising, given her l ...

  4. 【刷题】BZOJ 4391 [Usaco2015 dec]High Card Low Card

    Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of ...

  5. [USACO15DEC]高低卡(白金)High Card Low Card (Platinum)

    题目描述 Bessie the cow is a hu e fan of card games, which is quite surprising, given her lack of opposa ...

  6. BZOJ4391 High Card Low Card [Usaco2015 dec](贪心+线段树/set库

    正解:贪心+线段树/set库 解题报告: 算辣直接甩链接qwq 恩这题就贪心?从前往后从后往前各推一次然后找一遍哪个地方最大就欧克了,正确性很容易证明 (这里有个,很妙的想法,就是,从后往前推从前往后 ...

  7. [bzoj4391] [Usaco2015 dec]High Card Low Card 贪心 线段树

    ---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化 ...

  8. bzoj4391 [Usaco2015 dec]High Card Low Card

    传送门 分析 神奇的贪心,令f[i]表示前i个每次都出比对方稍微大一点的牌最多能赢几次 g[i]表示从i-n中每次出比对方稍微小一点的牌最多赢几次 ans=max(f[i]+g[i+1]) 0< ...

  9. [USACO15DEC]High Card Low Card (Platinum)

    https://www.zybuluo.com/ysner/note/1300791 题面 贝西和她的朋友艾尔西正在玩这个简单的纸牌游戏.游戏有\(2N\)张牌,牌上的数字是\(1\)到\(2N\). ...

随机推荐

  1. Regionserver启动后又关闭

    今天启动hbase shell,输入hbase命令时报错: ERROR [regionserver/regionserver1/172.18.0.61:16020] reggionserver.HRe ...

  2. 20155227《网络对抗》Exp3 免杀原理与实践

    20155227<网络对抗>Exp3 免杀原理与实践 实践内容 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,自己利用shellcode编程等 ...

  3. 2017-2018-2 20155229《网络对抗技术》Exp1:逆向及Bof基础实践

    逆向及Bof基础实践 实践基础知识 管道命令: 能够将一个命令的执行结果经过筛选,只保留需要的信息. cut:选取指定列. 按指定字符分隔:只显示第n 列的数据 cut -d '分隔符' -f n 选 ...

  4. 《图说VR入门》——入门汇总

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/53818922 作者:car ...

  5. PX Deq: Execution Msg 等待事件

    可参考 MOS文档: WAITEVENT: "PX Deq Credit: send blkd" (Doc ID 271767.1) P1 = sleeptime/senderid ...

  6. Caffe 深度学习框架上手教程

    Caffe 深度学习框架上手教程   blink 15年1月   Caffe (CNN, deep learning) 介绍 Caffe -----------Convolution Architec ...

  7. Ajax 上传文件(input file FormData)

    FormData对象用以将数据编译成键值对,以便用XMLHttpRequest来发送数据.其主要用于发送表单数据,但亦可用于发送带键数据(keyed data),而独立于表单使用. jQuery Aj ...

  8. JavaScript快速入门-ECMAScript本地对象(String)

    一.String对象 String对象和python中的字符串一样,也有很多方法,这些方法大概分为以下种类: 1.索引和查找 1.charAt()   返回指定位置的字符. 2.charCodeAt( ...

  9. Zabbix实战-简易教程--大型分布式监控系统实现Agent批量快速接入

    一.分布式架构 相信使用zabbix的大神都熟悉他的分布式架构,分布式的优势相当明显,分而治之.比如目前我的架构图如下: 那么,对将要接入监控系统的任何一个agent如何快速定位,并进行接入呢?  问 ...

  10. nvm管理不同版本的node和npm

    写在前面 nvm(nodejs version manager)是nodejs的管理工具,如果你需要快速更新node版本,并且不覆盖之前的版本:或者想要在不同的node版本之间进行切换:使用nvm来安 ...