【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\). ...
随机推荐
- 【stylus】stylus在webstrom中的识别
<style lang="stylus" rel="stylesheet/stylus"> @import './common/stylus/mix ...
- Sign in with the app-specific password you generated. If you forgot the app-specific password or need to create a new one, go to appleid.apple.com
iOS打包报错信息如下:Sign in with the app-specific password you generated. If you forgot the app-specific pas ...
- 实测—fft IP核使用(包括ifft的配置使用)
Vivado xilinx fft9.0 使用笔记: ****注 仿真实测1024点的转换需要经过1148个时钟周期才能得到转换结果: 模块配置信号含义请参考pg109文档手册(写的贼烂会看晕),不详 ...
- 2017-2018-2 20155224『网络对抗技术』Exp4:恶意代码分析
原理与实践说明 实践目标 监控你自己系统的运行状态,看有没有可疑的程序在运行. 分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals,systr ...
- Python 语言简介
Python是一种计算机程序设计语言.你可能已经听说过很多种流行的编程语言,比如非常难学的C语言,非常流行的Java语言,适合初学者的Basic语言,适合网页编程的JavaScript语言等等. 那P ...
- SimpleDateFormat-时间格式化中的大小写字符
一.SimpleDateFormat: 这个类是用来格式化date类型数据为指定格式的时间的 使用的而时候,总是区分不清 yyyy-mm-dd yyyy-MM-dd 而使用不同的大小写字符格式化出来的 ...
- MFC CHotKeyCtrl控件
知识点: CHotKeyCtrl控件 获取热键数据 注册热键 响应热键事件 一.CHotKeyCtrl控件 void SetHotKey( WORD wVirtualKeyCode, WORD wMo ...
- adb连接手机的两种方式
adb连接手机进行调试有两种方式,一种使用USB线,一种使用无线WiFi. 第一种 使用USB线连接 1. 在手机上启用USB调试 2. CMD窗口输入adb devices,此时可以看到自己的设备 ...
- 【第五课】LNMP环境的入门
目录 一. LNMP环境介绍 二.Mysql的二进制免编译安装 三.PHP 7.2.5编译部署 四.Nginx的编译安装 五.YUM安装Nginx 一. LNMP环境介绍 LNMP(Linux + N ...
- 行级安全(Row-Level Security)
通过授予和拒绝(Grant/Deny)命令控制用户的权限,只能控制用户对数据库对象的访问权限,这意味着,用户访问的粒度是对象整体,可以是一个数据表,或视图等,用户要么能够访问数据库对象,要么没有权限访 ...