【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. Modelsim SE 和 Quartus II 编译器(综合器)的区别

    当对目标模块进行RTL描述后,习惯先会用Modelsim做一下功能仿真.当我们写好Tensbench文件,直接在Modelsim SE中对源文件(design和Testbench)进行编译时,如果源文 ...

  2. Java基础—基础语法与常用命令

    一.基础语法 1.case不加break会有穿透效果 根据阿里规范,严禁省略default语句,即使它一句话也没有 2.for循环执行顺序: for(初始化1;条件2;迭代运算3){ 循环体4: } ...

  3. 一、Django前后端交互之Ajax和跨域问题

    一.Ajax介绍 1.概述 AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术.AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步Jav ...

  4. Error:Could not find common.jar (android.arch.core:common:1.0.0)

    Error:Could not find common.jar (android.arch.core:common:1.0.0). Searched in the following location ...

  5. js获取浏览器对象的信息

    js中有一个对象叫 navigator,navigator 对象包含有关浏览器的信息.所有的浏览器都支持该对象. 其中经常用到的是 navigator.userAgent 属性,通常,它是在 navi ...

  6. eclipse中设置项目的编码方式

    1.windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->Workspace,右侧Text file encoding ...

  7. Istio 流量治理功能原理与实战

    一.负载均衡算法原理与实战 负载均衡算法(load balancing algorithm),定义了几种基本的流量分发方式,在Istio中共有4种标准负载均衡算法. •Round_Robin: 轮询算 ...

  8. mac osx 初次使用PHP环境搭建

    非常简单,一共2个步骤: Step1: 启动Apache mac osx 系统默认安装Apache服务. 首先打开terminal,输入: sudo apachectl start 如果需要输入密码, ...

  9. 《Linux内核分析》第三周笔记 构造一个简单的Linux系统MenuOS

    构造一个简单的Linux系统MenuOS 一.linux内核源代码简介 三大法宝(存储程序计算机.函数调用堆栈.中断)和两把宝剑(中断上下文的切换:保存现场和恢复现场.进程上下文的切换) 1.在lin ...

  10. SpringMVC(三)-- springmvc的系统学习之数据的处理,乱码及restful

    资源:尚学堂 邹波 springmvc框架视频 一.提交数据的处理 1.提交的域名称和处理方法的参数一致 (1)提交的数据:http://localhost:8080/data/hello.do?na ...