传送门

分析

神奇的贪心,令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. KVM- 日常管理与配置

    KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理. 1.  查看KVM虚拟机配置文件及运行状态 (1) KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostar ...

  2. stl_relops.h

    stl_relops.h // Filename: stl_relops.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http ...

  3. Python 3.5 socket OSError: [Errno 101] Network is unreachable

    /******************************************************************************** * Python 3.5 socke ...

  4. BZOJ- 3142:数列 (数学)

    题意:给出N,K,M,P.求有多少长度为K的序列A,满足:(1)首项为正整数:(2)递增数列:(3)相邻两项的差小于等于m:(4)最后一个数小于等于N. 思路:根据差分来算数量. #include&l ...

  5. poj2374 Fence Obstacle Course[线段树+DP]

    https://vjudge.net/problem/POJ-2374 吐槽.在这题上面磕了许久..英文不好题面读错了qwq,写了个错的算法搞了很久..A掉之后瞥了一眼众多julao题解,**,怎么想 ...

  6. Unity Shader 创建程序纹理贴图

    创建一个脚本 附加到一个游戏体上 using UnityEngine;using System.Collections; public class ProceduralTexture : MonoBe ...

  7. UGUI技巧

    http://www.cnblogs.com/suoluo/p/5427514.html Text中的可以单独指定某些文字的颜色,只需将想要变色的文本放在<color=**></co ...

  8. Azure VM的加速网络

    Azure的VM在经过几代发展后已经有多种硬件类型.目前Azure China的多种机型都配置了FPGA卡,可以实现网络加速.本文将介绍Azure的加速网络相关的内容. 一. 加速网络的硬件准备 下图 ...

  9. 使用PowerShell在Azure China创建Data Warehouse

    微软的Azure Data Warehouse是基于MPP架构的分布式系统: Control Node负责管理系统和接受用户的请求,Compute Node负责计算. 目前在国内Azure Data ...

  10. MyCAT 1.6 安装部署

    1 mycat 安装部署 1 下载解压Mycat-server-1.6-RELEASE-20161010173036-linux.tar.gz 到/usr/local/mycat 2 下载解压jdk- ...