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 ...
随机推荐
- Linux定时清理30天前的Tomcat日志脚本
一.在tomcat的log路径下新建.sh脚本文件clean.sh,内容如下:#!/bin/bashlogs_path="/mnt/tomcat/apache-tomcat-8.5.23/l ...
- 开元java开发工具
开元java开发工具 http://www.hutool.cn/
- Subversion Server Edge用户权限设置简介
Subversion Server Edge用户权限可分为两种,一种为按用户权限,一种为按组权限设置 1.按用户设置权限 [codeLibrary:/] //对整个代码库 *=r //所有用户 ...
- Spark编程环境搭建及WordCount实例
基于Intellij IDEA搭建Spark开发环境搭建 基于Intellij IDEA搭建Spark开发环境搭——参考文档 ● 参考文档http://spark.apache.org/docs/la ...
- 《从0到1学习Flink》—— Flink Data transformation(转换)
前言 在第一篇介绍 Flink 的文章 <<从0到1学习Flink>-- Apache Flink 介绍> 中就说过 Flink 程序的结构 Flink 应用程序结构就是如上图 ...
- Python list, dict, set, tuple
list方法 append: 添加一个新的元素到末尾 extend: 扩展元素 insert: 在任何位置插入元素 pop: 弹出末尾的元素 remove: remove first occurren ...
- java简单使用netty
一 整合 由于本人的学过的技术太多太乱了,于是决定一个一个的整合到一个springboot项目里面. 附上自己的github项目地址 https://github.com/247292980/spri ...
- MVC与MVVM的关系
什么是MVC? M(Model数据层) 职能单一,只负责操作数据库,执行对于的 Sql 语句,进行数据的CRUD C: create 增加 R: Read 读取 U: update 修改 D: Del ...
- Elasticsearch-2.3 (OpenLogic CentOS 7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: elasticsearch-2.3 application server basic software big data elasticsearch ...
- Hyper-V 2016 配置管理系列(部署篇)
Hyper主机前提准备以后,我们开始Hyper-V Cluster 群集配置 准备验证Cluster 群集 : 1)打开群集管理器,点击"validate Configuration&quo ...