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

题面

BZOJ

题解

预处理前缀后缀的结果,中间找个地方合并就好了。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<set>
  8. using namespace std;
  9. #define MAX 100100
  10. inline int read()
  11. {
  12. int x=0;bool t=false;char ch=getchar();
  13. while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
  14. if(ch=='-')t=true,ch=getchar();
  15. while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
  16. return t?-x:x;
  17. }
  18. int a[MAX],b[MAX],n,tot,ans;
  19. bool vis[MAX];
  20. int s1[MAX],s2[MAX];
  21. set<int> S;
  22. int main()
  23. {
  24. n=read();
  25. for(int i=1;i<=n;++i)vis[a[i]=read()]=true;
  26. for(int i=1;i<=n+n;++i)if(!vis[i])b[++tot]=i;
  27. for(int i=1;i<=n;++i)S.insert(b[i]);
  28. for(int i=1;i<=n;++i)
  29. {
  30. set<int>::iterator it=S.upper_bound(a[i]);
  31. if(it!=S.end())s1[i]=s1[i-1]+1,S.erase(it);
  32. else s1[i]=s1[i-1];
  33. }
  34. S.clear();
  35. for(int i=1;i<=n;++i)S.insert(-b[i]);
  36. for(int i=n;i;--i)
  37. {
  38. set<int>::iterator it=S.upper_bound(-a[i]);
  39. if(it!=S.end())s2[i]=s2[i+1]+1,S.erase(it);
  40. else s2[i]=s2[i+1];
  41. }
  42. for(int i=0;i<=n;++i)ans=max(ans,s1[i]+s2[i+1]);
  43. printf("%d\n",ans);
  44. return 0;
  45. }

【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  8. bzoj4391 [Usaco2015 dec]High Card Low Card

    传送门 分析 神奇的贪心,令f[i]表示前i个每次都出比对方稍微大一点的牌最多能赢几次 g[i]表示从i-n中每次出比对方稍微小一点的牌最多赢几次 ans=max(f[i]+g[i+1]) 0< ...

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

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

随机推荐

  1. 关于NLB的群集操作模式知识 (转载)

    单播:单播模式是指各节点的网络适配器被重新指定了一个虚拟MAC(由02-bf和群集IP地址组成确保此MAC的唯一性).由于所有绑定群集的网络适配器的MAC都相同,所以在单网卡的情况下,各节点之间是不能 ...

  2. 保存网格(mesh)到磁盘上

    Unity提供了很方便的工具来保存mesh之类的,下面的代码挂在GameObject上后,按下F键能把mesh(该GameObject必须有mesh组件)保存到磁盘的Assets目录下.在磁盘上是.a ...

  3. ubuntu14.04安装jupyter notebook

    1.使用pip安装Jupyter notebook: pip install jupyter notebook 2.创建Jupyter默认配置文件: jupyter notebook --genera ...

  4. C# read write ini file

    [DllImport("kernel32")] private static extern long WritePrivateProfileString(string sectio ...

  5. Java通过pinyin4j实现汉字转拼音

       碰到个需求,需要按用户名字的首字母来排序.这就需要获取汉字对应的拼音了,突然就想起了pinyin4j这个jar包,于是就开始写了个汉字转拼音的工具类.在此记录一下,方便后续查阅 一.Pom依赖 ...

  6. 解决debug到jdk源码时不能查看变量值的问题

    目录 如何跟踪jdk源码 1. 编译源码 2. 关联源码 3. 大功告成 如何跟踪jdk源码 看到这个标题大概大家都会在心里想谁还跟踪个源码呀,在eclipse中打个断点,以debug的方式运行,然后 ...

  7. switch语句的执行过程

    switch语句的执行规则如下: 1.从第一个case开始判断,不匹配则跳到下一个case继续判断: 2.遇到break则跳出switch语句: 3.default一般是没有匹配项才执行的,一般是放在 ...

  8. VMware桥接模式连接局域网

    今天尝试虚拟机直连家里的局域网,用于方便另外一台主机使用家里的虚拟机. 本次连接方式是通过桥接方式,但由于'桥接到'选项默认自动,导致无法连通,最终以下步骤完成配置: 第一步:确认本地网关地址 第二步 ...

  9. 如何完全卸载VS2010(亲自体验过) (转)

    1.首先用360卸载,当卸载完成后,提示有残余的话,就强力清除 2,接着,下载IobitUninstaller工具 3.按照下面进行卸载 1.Microsoft .NET Framework 4 框架 ...

  10. Unity游戏AI记录(2d横板为例)

    using System.Collections;using System.Collections.Generic;using UnityEngine; public class GeneralPeo ...