传送门

分析

神奇的贪心,令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. Memcache mutex设计模式

    Memcache mutex设计模式 转自:https://timyang.net/programming/memcache-mutex/ 场景 Mutex主要用于有大量并发访问并存在cache过期的 ...

  2. BZOJ - 2588 Spoj 10628. Count on a tree (可持久化线段树+LCA/树链剖分)

    题目链接 第一种方法,dfs序上建可持久化线段树,然后询问的时候把两点之间的所有树链扒出来做差. #include<bits/stdc++.h> using namespace std; ...

  3. SaaS模式实现架构

    SaaS模式实现架构 https://blog.csdn.net/xwq911/article/details/50630266 1. 数据库层: 数据库这一层的设计模式是很清晰的,无外乎只有3种方案 ...

  4. LeetCode Largest Palindrome Product

    原题链接在这里:https://leetcode.com/problems/largest-palindrome-product/description/ 题目: Find the largest p ...

  5. java 收集linux信息

    public class MachineCollector  implements Runnable{  private static int DEFAULT_INTERVAL = 30;  priv ...

  6. 使用dumpbin命令查看dll导出函数及重定向输出到文件【轉】

    查看dll导出函数,一般使用Viewdll等第三方工具. VS开发环境中,可以查看32位和64位的dll.具体使用方法如下: 1. 进入VS开发环境,然后Tools -> Visual stud ...

  7. 修改分区后的 Grub rescue

    声明:这里用到的知识不是原创,综合了几篇教程的成果.找的时候比较混乱,所以来源已经不确定.希望原作者见谅. 系统是Windows 8.1 和 Ubuntu 14.04, Windows是先装的, gr ...

  8. BZOJ1116:[POI2008]CLO

    浅谈并查集:https://www.cnblogs.com/AKMer/p/10360090.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php? ...

  9. Maven Build错误。

    错误: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal ...

  10. springmvc----demo---login---bai

    web.xml配置: <?xml version="1.0" encoding="UTF-8"?> <web-app version=&quo ...