题目描述

Bessie the cow is a hu e fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a completely predictable fashion! Nonetheless, it can still be a challenge for Bessie to figure out how to win.

Bessie and her friend Elsie are currently playing a simple card game where they take a deck of 2N2N2N cards, conveniently numbered 1…2N1 \ldots 2N1…2N , and divide them into NNN cards for Bessie and NNN cards for Elsie. The two then play NNN rounds, where in each round Bessie and Elsie both play a single card. Initially, the player who plays the highest card earns a point. However, at one point during the game, Bessie can decide to switch the rules so that for the rest of the game, the player who plays the lowest card wins a point. Bessie can choose not to use this option, leaving the entire game in "high card wins" mode, or she can even invoke the option right away, making the entire game follow the "low card wins" rule.

Given that Bessie can predict the order in which Elsie will play her cards, please determine the maximum number of points Bessie can win.

贝西很喜欢玩一种纸牌游戏。

贝西和她的朋友艾尔西正在玩这个简单的纸牌游戏。游戏有2N张牌,牌上的数字是1到2N。把这些牌分成两份,贝西有N张,艾尔西有另外N张。接下来她们进行N轮出牌,每次各出一张牌。一开始,谁出的牌上的数字大,谁就获得这一轮的胜利。贝西有一个特殊权利,她可以在任意一个时刻把原本数字大的获胜的规则改成数字小的获胜,这个改变将会一直持续到游戏结束。特别的,贝西可以从第一轮开始就使用小牌获胜的规则,也可以直到最后一轮都还杂使用大牌获胜的规则。

现在,贝西已经知道了艾尔西出牌的顺序,她想知道她最多能够赢多少轮。

输入输出格式

输入格式:

The first line of input contains the value of N ( 2≤N≤50,0002 \leq N \leq 50,0002≤N≤50,000 ).

The next N lines contain the cards that Elsie will play in each of the

successive rounds of the game. Note that it is easy to determine Bessie's cards

from this information.

输出格式:

Output a single line giving the maximum number of points Bessie can score.

输入输出样例

输入样例#1:

4
1
8
4
3
输出样例#1:

3

说明

Here, Bessie must have cards 2, 5, and 6, and 7 in her hand, and she can use

these to win at most 3 points. For example, she can defeat the 1 card and then

switch the rules to "low card wins", after which she can win two more rounds.

提交地址 : Bzoj4391

F1[i] 表示从头开始按照方案一的最大赢的数;

F2[i] 表示从胃开始按照方案二的最大赢的数;

那么答案就是max(F1[i] + F2[i+1]);

合理性分析:

(坑)

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
#define regi register int n, k;
int a[], b[], cnt;
int use[]; int f1[], f2[]; set <int> s1, s2; int main()
{
cin >> n; for (regi int i = ; i <= n ; i ++){
scanf("%d", &b[i]);
use[b[i]] = ;
} for (regi int i = ; i <= * n ; i ++){
if (!use[i])
{
a[++cnt] = i;
s1.insert(i);
s2.insert(-i);
}
} for (register int i = ; i <= n ; i ++){
set <int> :: iterator it = s1.lower_bound(b[i]);
if (it != s1.end())
{
s1.erase(it);
f1[i] = f1[i-] + ;
}
else
{
f1[i] = f1[i-];
}
} for (register int i = n ; i >= ; i --){
set <int> ::iterator it = s2.lower_bound(-b[i]);
if (it != s2.end())
{
s2.erase(it);
f2[i] = f2[i+] + ;
}
else
{
f2[i] = f2[i+];
}
} int ans = f2[];
for (register int i = ; i <= n ; i ++){
ans = max(ans, f1[i] + f2[i+]);
} /* for (regi int i = 1 ; i <= n ; ++i)
{
printf("%d ", f1[i]);
}
puts("");
for (register int i = 1 ; i <= n ; i ++)
{
printf("%d ", f2[i]);
}
puts("");*/ cout << ans << endl;
return ;
}

zZhBr

[USACO15DEC]高低卡(白金)High Card Low Card (Platinum)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. bzoj4391 [Usaco2015 dec]High Card Low Card

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

随机推荐

  1. Centos7上安装jdk8

    CentOS7 下安装jdk8环境 1 检查服务器环境 首先,我们需要检查一下服务器是否安装过java环境,可以使用如下命令: java -version 如果已经安装有java环境,会出现类似于以下 ...

  2. [kuangbin带你飞]专题一 简单搜索 题解报告

    又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...

  3. charles 重写工具/rewrite Srttings

    本文参考:charles 重写工具 rewrite Srttings 重写工具/rewrite Srttings and rewrite rule 功能:在通过charles时修改请求和响应 重写工具 ...

  4. C# 缓存的实现

    缓存的实现 我们不是做第三方比如Redis等的缓存实现,而是根据实际情况,基于C#上做一些环境变量的保存,方便项目使用. 1.系统全局变量 很多时候,在系统运行开始,需要对系统的运行参数进行保存,以便 ...

  5. TensorFlow2.0(二):数学运算

    1 基本运算:加(+).减(-).点乘(*).除(/).地板除法(//).取余(%) 基本运算中所有实例都以下面的张量a.b为例进行: >>> a = tf.random.unifo ...

  6. [洛谷日报第39期]比STL还STL?——pbds

    [洛谷日报第39期]比STL还STL?——pbds   洛谷科技 发布时间:18-08-3116:37 __gnu_pbds食用教程 引入 某P党:“你们C++的STL库真强(e)大(xin),好多数 ...

  7. Maven报错: Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp

    郁闷了两天,创建maven项目时,eclipse报错:Could not resolve artifact org.apache.maven.archetypes:maven-archetype-we ...

  8. 每个人都要学的图片压缩终极奥义,有效解决 Android 程序 OOM

    # 由来 在我们编写 Android 程序的时候,几乎永远逃避不了图片压缩的难题.除了应用图标之外,我们所要显示的图片基本上只有两个来源: 来自网络下载 本地相册中加载 不管是网上下载下来的也好,还是 ...

  9. mysql replace into使用

    使用mysql插入数据时,我们通常使用的是insert into来处理,replace into有时可以替代insert into功能,但replace into也有自己的用法 准备一张测试表: CR ...

  10. 死磕 java线程系列之创建线程的8种方式

    (手机横屏看源码更方便) 问题 (1)创建线程有哪几种方式? (2)它们分别有什么运用场景? 简介 创建线程,是多线程编程中最基本的操作,彤哥总结了一下,大概有8种创建线程的方式,你知道吗? 继承Th ...