传送门

分析

神奇的贪心,令f[i]表示前i个每次都出比对方稍微大一点的牌最多能赢几次

g[i]表示从i-n中每次出比对方稍微小一点的牌最多赢几次

ans=max(f[i]+g[i+1]) 0<=i<=n

虽然方案可能会重合但是这是可行的

1:因为限制比原题目宽,所以ans>=真实的答案

2:对于重复取的数a,如果集合中有个没取的数<a,那么在用小的赢的时候可以代替a

如果>a,那么在用大的赢时可以代替a

用set来记录最接近的数

代码

#include<bits/stdc++.h>
using namespace std;
set<int>a,b;
int f[],g[],is[],d[];
int main(){
int n,m,i,j,k;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&d[i]);
is[d[i]]=;
}
for(i=;i<=*n;i++)
if(!is[i]){
a.insert(i);
b.insert(-i);
}
for(i=;i<=n;i++){
set<int>::iterator pl=a.lower_bound(d[i]);
if(pl!=a.end())a.erase(pl),f[i]=f[i-]+;
else f[i]=f[i-];
}
for(i=n;i>;i--){
set<int>::iterator pl=b.lower_bound(-d[i]);
if(pl!=b.end())b.erase(pl),g[i]=g[i+]+;
else g[i]=g[i+];
}
int Ans=;
for(i=;i<=n;i++)Ans=max(Ans,f[i]+g[i+]);
cout<<Ans<<endl;
return ;
}

bzoj4391 [Usaco2015 dec]High Card Low Card的更多相关文章

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

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

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

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

  3. [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 ...

  4. 【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 ...

  5. 【刷题】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 ...

  6. [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 ...

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

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

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

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

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

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

随机推荐

  1. hbase_异常_04_util.FSUtils: Waiting for dfs to exit safe mode...

    一.异常现象 启动hbase的时,hbase的日志中可以发现: Waiting for dfs to exit safe mode... 然后就抛异常了 2018-03-22 17:00:28,994 ...

  2. L119

    A big collaboration is trying to understand diseases of the psycheDiseases of the psyche have always ...

  3. 4.MySQL优化---多表查询优化

     整理自互联网 一.多表查询连接的选择: 相信这内连接,左连接什么的大家都比较熟悉了,当然还有左外连接什么的,基本用不上我就不贴出来了.这图只是让大家回忆一下,各种连接查询. 然后要告诉大家的是,需要 ...

  4. 3.16 draw 3.17 更新函数

    3.16 draw virtual void draw(); void HelloWorld::draw() { CCSize size = CCDirector::sharedDirector()- ...

  5. LeetCode LFU Cache

    原题链接在这里:https://leetcode.com/problems/lfu-cache/?tab=Description 题目: Design and implement a data str ...

  6. linux 内核的链表操作(好文不得不转)

    以下全部来自于http://www.ibm.com/developerworks/cn/linux/kernel/l-chain/index.html 无任何个人意见. 本文详细分析了 2.6.x 内 ...

  7. ubuntu更改用户登录密码

    sudo passwd user(root或对应的用户名)

  8. [转]你知道用AngularJs怎么定义指令吗?--很详细

    前言 最近学习了下angularjs指令的相关知识,也参考了前人的一些文章,在此总结下. 欢迎批评指出错误的地方.   Angularjs指令定义的API AngularJs的指令定义大致如下 ang ...

  9. SVN 命令使用-***

    1.检出到某一版本: svn checkout -r 974  svn://220.231.xx.xx/仓库名 svn checkout  svn://220.231.xx.xx/仓库名 svn ex ...

  10. 三层自动生成 完整源代码(for oracle)

    using Oracle.DataAccess.Client; using System; using System.Collections.Generic; using System.Compone ...