传送门

分析

神奇的贪心,令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. IE9 placeholder 不兼容的解决

    坑爹的IE9-,真的是够够的了,不过公司不要求兼容这个玩意了,自己觉得兼容这个鬼还是挺有挑战性的,自己也碰到不少难题,一个个解决. css: .placeholderColor { color : # ...

  2. CodeForces - 688C:NP-Hard Problem (二分图&带权并查集)

    Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex c ...

  3. Win7服务器搭建实例教程:教你Win7如何搭建Web服务器【转载】

    原文地址:http://www.pc841.com/article/20140607-30534.html 局域网Web服务器的主要功能是实现资源共享,同时借助于局域网服务器访问页面可有效的实现信息的 ...

  4. 表有外键所以delete报错了,这里有2种办法处理:

    表有外键所以delete报错了,这里有2种办法处理: (1)      临时设置外键失效 (2)      删除表涉及到的外键的表的数据 2.外键失效的处理方案 mysql> SET FOREI ...

  5. 【转】Flash AS3 保存图片到本地

    核心提示:如果你想保存从视频,图表或表格中获取的图片数据到本地,可以使用BitmapData类.   原文地址:   http://www.adobe.com/cfusion/communityeng ...

  6. Windows命令查看文件的MD5/SHA1/SHA256

    certutil -hashfile "D:\Tools\Microsoft\SqlServer\2016\ct_sql_server_2016_enterprise_x64_dvd_869 ...

  7. MySQL insert插入

    使用INSERT语句插入新数据 语法:INSERT [INTO] tbl_name [(col_name,...)] VALUES (pression,...),…      INSERT [INTO ...

  8. ORACLE显式授权

    同一数据库 两个不同用户 user1 user2 user1里面有一张表 table1 在user2里面创建synonymcreate synonym sy1 for user1.table1; 创建 ...

  9. Python:内置split()方法

    描述 Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串 语法 split()方法语法: str.split(str="&qu ...

  10. canvas图形组合

    代码: 1 /** 2 * Created by Administrator on 2016/1/27. 3 */ 4 function draw (id){ 5 var canvas = docum ...