【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
题面
题解
预处理前缀后缀的结果,中间找个地方合并就好了。
#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(贪心)的更多相关文章
- 【题解】P3129高低卡(白金)High Card Low Card
[题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规 ...
- [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 ...
- 【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 ...
- 【刷题】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 ...
- [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 ...
- BZOJ4391 High Card Low Card [Usaco2015 dec](贪心+线段树/set库
正解:贪心+线段树/set库 解题报告: 算辣直接甩链接qwq 恩这题就贪心?从前往后从后往前各推一次然后找一遍哪个地方最大就欧克了,正确性很容易证明 (这里有个,很妙的想法,就是,从后往前推从前往后 ...
- [bzoj4391] [Usaco2015 dec]High Card Low Card 贪心 线段树
---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化 ...
- bzoj4391 [Usaco2015 dec]High Card Low Card
传送门 分析 神奇的贪心,令f[i]表示前i个每次都出比对方稍微大一点的牌最多能赢几次 g[i]表示从i-n中每次出比对方稍微小一点的牌最多赢几次 ans=max(f[i]+g[i+1]) 0< ...
- [USACO15DEC]High Card Low Card (Platinum)
https://www.zybuluo.com/ysner/note/1300791 题面 贝西和她的朋友艾尔西正在玩这个简单的纸牌游戏.游戏有\(2N\)张牌,牌上的数字是\(1\)到\(2N\). ...
随机推荐
- 关于NLB的群集操作模式知识 (转载)
单播:单播模式是指各节点的网络适配器被重新指定了一个虚拟MAC(由02-bf和群集IP地址组成确保此MAC的唯一性).由于所有绑定群集的网络适配器的MAC都相同,所以在单网卡的情况下,各节点之间是不能 ...
- 保存网格(mesh)到磁盘上
Unity提供了很方便的工具来保存mesh之类的,下面的代码挂在GameObject上后,按下F键能把mesh(该GameObject必须有mesh组件)保存到磁盘的Assets目录下.在磁盘上是.a ...
- ubuntu14.04安装jupyter notebook
1.使用pip安装Jupyter notebook: pip install jupyter notebook 2.创建Jupyter默认配置文件: jupyter notebook --genera ...
- C# read write ini file
[DllImport("kernel32")] private static extern long WritePrivateProfileString(string sectio ...
- Java通过pinyin4j实现汉字转拼音
碰到个需求,需要按用户名字的首字母来排序.这就需要获取汉字对应的拼音了,突然就想起了pinyin4j这个jar包,于是就开始写了个汉字转拼音的工具类.在此记录一下,方便后续查阅 一.Pom依赖 ...
- 解决debug到jdk源码时不能查看变量值的问题
目录 如何跟踪jdk源码 1. 编译源码 2. 关联源码 3. 大功告成 如何跟踪jdk源码 看到这个标题大概大家都会在心里想谁还跟踪个源码呀,在eclipse中打个断点,以debug的方式运行,然后 ...
- switch语句的执行过程
switch语句的执行规则如下: 1.从第一个case开始判断,不匹配则跳到下一个case继续判断: 2.遇到break则跳出switch语句: 3.default一般是没有匹配项才执行的,一般是放在 ...
- VMware桥接模式连接局域网
今天尝试虚拟机直连家里的局域网,用于方便另外一台主机使用家里的虚拟机. 本次连接方式是通过桥接方式,但由于'桥接到'选项默认自动,导致无法连通,最终以下步骤完成配置: 第一步:确认本地网关地址 第二步 ...
- 如何完全卸载VS2010(亲自体验过) (转)
1.首先用360卸载,当卸载完成后,提示有残余的话,就强力清除 2,接着,下载IobitUninstaller工具 3.按照下面进行卸载 1.Microsoft .NET Framework 4 框架 ...
- Unity游戏AI记录(2d横板为例)
using System.Collections;using System.Collections.Generic;using UnityEngine; public class GeneralPeo ...