【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\). ...
随机推荐
- Java Web乱码分析及解决方案
1. 什么是URL编码. URL编码是一种浏览器用来打包表单输入的格式,浏览器从表单中获取所有的name和其对应的value,将他们以name/value编码方式作为URL的一部分或者分离的发送到服 ...
- CGAL学习:数据类型
CGAL 4.13 - Number Types 1 Introduction(介绍:略) 涉及到的数大致有3种:一是整数,二是有理数,三是浮点数.有理数可以用2个整数表示.精度上可分为任意精度和固定 ...
- 20155227《网络对抗》Exp8 Web基础
20155227<网络对抗>Exp8 Web基础 实验内容 (1)Web前端HTML (2)Web前端javascipt (3)Web后端:MySQL基础:正常安装.启动MySQL,建库. ...
- mfc 类模板
类模板 创建类模板 添加成员变量 添加成员函数 定义类模板对象 一.创建类模板 template <class T,class T2> template <class T> 二 ...
- python 回溯法 子集树模板 系列 —— 3、0-1背包问题
问题 给定N个物品和一个背包.物品i的重量是Wi,其价值位Vi ,背包的容量为C.问应该如何选择装入背包的物品,使得放入背包的物品的总价值为最大? 分析 显然,放入背包的物品,是N个物品的所有子集的其 ...
- wkhtmltopdf 参数介绍
wkhtmltopdf [OPTIONS]... <input file> [More input files] <output file> 常规选项 --allow &l ...
- 架构师修练 I - 超级代码控
可实现的是架构,空谈是概念 So don't tell me the concepts show me the code! “不懂编码的架构师不是好架构师” 好架构师都是超级代码控. 代码是最好 ...
- 【源码】进入ASP.NET MVC流程的大门 - UrlRoutingModule
UrlRoutingModule的功能 在ASP.NET MVC的请求过程中,UrlRoutingModule的作用是拦截当前的请求URL,通过URL来解析出RouteData,为后续的一系列流程提供 ...
- C#_Winform_聊天机器人
最近研究微信公众平台,搭建了一个微信聊天机器人,调用小黄鸡的公众接口,实现在线和小黄鸡聊天的功能. 接口调用不是很麻烦,不过是php版本,所以研究了一下C#的功能模块, Winfrom版 using ...
- 贪心Crossing river
英文题目: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...