bzoj4396[Usaco2015 dec]High Card Wins*
bzoj4396[Usaco2015 dec]High Card Wins
题意:
一共有2n张牌,Alice有n张,Bob有n张,每一局点数大的赢。知道Bob的出牌顺序,求Alice最多能赢几局。n≤50000。
题解:
贪心。将Alice和Bob的牌按点数大小排序,然后如果Alice当前牌能赢Bob当前牌就ans++否则就不断调整Bob的当前牌直到Alice当前牌能赢Bob当前牌。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define maxn 50010
using namespace std; inline int read(){
char ch=getchar(); int f=,x=;
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<='')x=x*+ch-'',ch=getchar();
return f*x;
}
int a[maxn],b[maxn],ans,n,tot; bool c[maxn*];
int main(){
n=read(); inc(i,,n)a[i]=read(),c[a[i]]=; inc(i,,*n)if(!c[i])b[++tot]=i; sort(a+,a+n+);
int p=,q=;
while(){
while(p<=n&&b[p]<a[q])p++; if(p==n+)break; ans++; p++; q++;
}
printf("%d",ans); return ;
}
20160908
bzoj4396[Usaco2015 dec]High Card Wins*的更多相关文章
- 4396: [Usaco2015 dec]High Card Wins
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 275 Solved: 175[Submit][Status][Discuss] Descriptio ...
- 【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 ...
随机推荐
- 深入理解React:懒加载(lazy)实现原理
目录 代码分割 React的懒加载 import() 原理 React.lazy 原理 Suspense 原理 参考 1.代码分割 (1)为什么要进行代码分割? 现在前端项目基本都采用打包技术,比如 ...
- winXP vc6行号显示插件-VC6LineNumberAddin方法-可用-无需注册
1.VC6LineNumberAddin 修改日期是2008.6.3可用,其它需要注册码 http://codefish.googlecode.com/files/VC%E6%98%BE%E7%A4% ...
- 运行 docker .... 命令报错
一.检查 Linux 上是有存在 docker [root@localhost bin]# docker version 不存在 docker 时,可以使用如下命令下载 docker [root@lo ...
- Redis自带压测工具(redis-benchmark.exe)
redis做压测: 可以用自带的redis-benchmark工具,使用简单 压测命令:redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 压测需要 ...
- 深度解剖dubbo源码---01dubbo的架构原理-探索.mp4
02内核解剖-dubbo自己的SPI实现.mp4 https://blog.csdn.net/prestigeding/article/details/80795708 https://segment ...
- Vue前端压缩图片
一.在组件包下新建compressImage.js // 压缩图片 // eslint-disable-next-line no-unused-vars export function compres ...
- EFCore-一对一配置外键小记2
前后两次遇到这样的错误: The property 'xx' on entity type 'xxxx' has a temporary value. Either set a permanent v ...
- Halcon斑点分析涉及算子及其高阶运用
涉及算子 获取图像 使用ROI 对齐ROI或图像 校正图像 基础内容这里不再重述 预处理图像(过滤) 基础: mean_image(平均平滑过滤),gauss_filter(高斯滤波),binomia ...
- Dysregulation of Exosome Cargo by Mutant Tau Expressed in Human-induced Pluripotent Stem Cell (iPSC) Neurons Revealed by Proteomics Analyses(蛋白质组学揭示了人诱导的多能干细胞(iPSC)神经元中表达的突变Tau对外泌体的失调) 解读人:梁玉婷
期刊名:MCP 发表时间:(2020年4月) IF:4.828 单位:Skaggs School of Pharmacy and Pharmaceutical Sciences, University ...
- 深度学习论文翻译解析(八):Rich feature hierarchies for accurate object detection and semantic segmentation
论文标题:Rich feature hierarchies for accurate object detection and semantic segmentation 标题翻译:丰富的特征层次结构 ...