4396: [Usaco2015 dec]High Card Wins
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 275 Solved: 175
[Submit][Status][Discuss]
Description
Bessie the cow is a huge 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 2N cards, conveniently numbered 1…2N, and divide them into N cards for Bessie and N cards for Elsie. The two then play N rounds, where in each round Bessie and Elsie both play a single card, and the player with the highest card earns a point.
Given that Bessie can predict the order in which Elsie will play her cards, please determine the maximum number of points Bessie can win.
奶牛Bessie和Elsie在玩一种卡牌游戏。一共有2N张卡牌,点数分别为1到2N,每头牛都会分到N张卡牌。
游戏一共分为N轮,因为Bessie太聪明了,她甚至可以预测出每回合Elsie会出什么牌。
每轮游戏里,两头牛分别出一张牌,点数大者获胜。
Bessie现在想知道,自己最多能获胜多少轮?
Input
The first line of input contains the value of N (1≤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
Output a single line giving the maximum number of points Bessie can score.
Sample Input
1
6
4
Sample Output
HINT
Here, Bessie must have cards 2, 3, and 5 in her hand, and she can use these to win at most 2 points by saving the 5 until the end to beat Elsie's 4.
Problem credits: Austin Bannister and Brian Dean
Source
set似乎可以强搞,利用set自排序的特性,再按照田忌赛马原则(?)大雾
#include<iostream>
#include<cstdio>
#include<set>
#include<iterator>
#include<algorithm>
using namespace std; int n,node=;
int a[];
set<int> S;
set<int>::iterator iter; int main()
{
scanf("%d",&n);
for(int i=;i<=*n;i++) S.insert(i);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
S.erase(a[i]);
}
sort(a,a+n);
for(iter=S.begin();iter!=S.end();iter++)
if(*iter>a[node]) node++;
printf("%d",node);
return ;
}
4396: [Usaco2015 dec]High Card Wins的更多相关文章
- bzoj4396[Usaco2015 dec]High Card Wins*
bzoj4396[Usaco2015 dec]High Card Wins 题意: 一共有2n张牌,Alice有n张,Bob有n张,每一局点数大的赢.知道Bob的出牌顺序,求Alice最多能赢几局.n ...
- 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...
- 【刷题】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 ...
- [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 ...
- 【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 ...
- [bzoj4391] [Usaco2015 dec]High Card Low Card 贪心 线段树
---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化 ...
- bzoj4391 [Usaco2015 dec]High Card Low Card
传送门 分析 神奇的贪心,令f[i]表示前i个每次都出比对方稍微大一点的牌最多能赢几次 g[i]表示从i-n中每次出比对方稍微小一点的牌最多赢几次 ans=max(f[i]+g[i+1]) 0< ...
- BZOJ 4390: [Usaco2015 dec]Max Flow
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 113[Submi ...
- bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec Memory Limit: 128 MB Description Farmer John ...
随机推荐
- BZOJ 1924 && Luogu P2403 [SDOI2010]所驼门王的宝藏 恶心建图+缩点DP
记住:map一定要这么用: if(mp[x[i]+dx[j]].find(y[i]+dy[j])!=mp[x[i]+dx[j]].end()) add(i,mp[x[i]+dx[j]][y[i]+dy ...
- 页面上AJAX调用数据
<div class="section page9" data-page='9'> <div class="global-section-wrp med ...
- Unity GameObject.Find 和 transform.Find
transform.Find(""); 找到子游戏对象,找自己找不到,能找到未激活的子游戏对象. 括号里可以是游戏对象的名字,也可以是层级. GameObject.Find(&qu ...
- Sqoop环境安装
环境下载 首先将下载的 sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz放到 /usr/hadoop/目录下(该目录可以自定义,一般为Hadoop集群安装目录),然 ...
- No lease on /目录: File does not exist. [Lease. Holder: DFSClient_NONMAPREDUCE_-2059237550_1, pendingcreates: 8]错误及解决方法
感觉程序员的世界真是一个变幻无常且精彩绝伦的世界,每次跑程序都会发现不一样的问题.今天跑MapReduce程序来统计邮箱次数时遇到了一个问题,明明一样的代码,别人能跑,我却跑不了.我相信,基本做这行的 ...
- Storm概念学习系列 之Worker工作者进程
不多说,直接上干货! Worker工作者进程 工作者进程(Worker)是一个java进程,执行拓扑的一部分任务.一个Worker进程执行一个Topology的子集,它会启动一个或多个Execut ...
- 《从0到1学习Flink》—— Flink 写入数据到 Kafka
前言 之前文章 <从0到1学习Flink>-- Flink 写入数据到 ElasticSearch 写了如何将 Kafka 中的数据存储到 ElasticSearch 中,里面其实就已经用 ...
- Ubuntu 14.04上安装Riak
一.安装riak 1. 安装包:riak_2.0.2-1_amd64.deb 路 径:~/software/riak_2.0.2-1_amd64.deb 2. 安装riak $ ...
- css钻石旋转实现
css钻石旋转实现: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- 未整理js
函数+对象=方法 方法是动作 有参数的函数=实例 使用new关键字和函数来创建一个实例 var p =new Point(1,1)//平面几何的点 表示遍历的语句样子: for(var i =0; i ...