洛谷P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述
Bessie and her friends are playing a unique version of poker involving a deck with \(N\) (\(1 \leq N \leq 100000\)) different ranks, conveniently numbered \(1..N\) (a normal deck has \(N = 13\)). In this game, there is only one type of hand the cows can play: one may choose a card labeled \(i\) and a card labeled j and play one card of every value from i to \(j\). This type of hand is called a "\(straight\)".
Bessie's hand currently holds \(a_i\) cards of rank \(i (0 \leq a_i \leq 100000\)). Help her find the minimum number of hands she must play to get rid of all her cards.
一个牛有\(N\)堆牌,每堆排数量不等。一只牛一次可以将第\(i\)张到第\(j\)张各打一张出去,问最少几次打完
输入输出格式
输入格式:
Line \(1\): The integer \(N\).
Lines \(2..1\)+\(N\): Line \(i\)+\(1\) contains the value of \(a_i\).
输出格式:
Line \(1\): The minimum number of straights Bessie must play to get rid of all her cards.
输入输出样例
输入样例#1:
5
2
4
1
2
3
输出样例#1:
6
说明
Bessie can play a straight from \(1\) to \(5\), a straight from \(1\) to \(2\), a straight from \(4\) to \(5\), two straights from \(2\) to \(2\), and a straight from \(5\) to \(5\), for a total of \(6\) rounds necessary to get rid of all her cards.
思路:双倍经验……跟\(noip2018\) \(Day1T1\)一样……本来还以为是线段树,所以才点进来。
代码:
#include<cstdio>
#include<cctype>
#define maxn 100007
#define ll long long
using namespace std;
int n,a[maxn];
ll ans;
inline int qread() {
char c=getchar();int num=0,f=1;
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) num=num*10+c-'0';
return num*f;
}
int main() {
n=qread();
for(int i=1;i<=n;++i) {
a[i]=qread();
if(a[i]>a[i-1]) ans+=a[i]-a[i-1];
}
printf("%lld\n",ans);
return 0;
}
洛谷P3078 [USACO13MAR]扑克牌型Poker Hands的更多相关文章
- 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands
P3078 [USACO13MAR]扑克牌型Poker Hands 题目描述 Bessie and her friends are playing a unique version of poker ...
- P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述 Bessie and her friends are playing a unique version of poker involving a deck with N (1 <= N ...
- 「Luogu P3078 [USACO13MAR]扑克牌型Poker Hands」
本题有\(O(N)\)的优秀做法,但是因为在考场上不一定能想到,就来分享一种\(O(N\log_2N)\)的做法.虽然有点慢,但是可以过. 前置芝士 线段树:提高组及以上必备内容,不会的同学可以学习一 ...
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
- 洛谷P3080 [USACO13MAR]牛跑The Cow Run
P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his ...
- 洛谷 P3079 [USACO13MAR]农场的画Farm Painting
P3079 [USACO13MAR]农场的画Farm Painting 题目描述 After several harsh winters, Farmer John has decided it is ...
- 洛谷2014选课(树型dp)
题目:https://www.luogu.org/problemnew/show/P2014 千万注意遍历 j 和 k 的边界! 0点很好用. siz很好用. #include<iostream ...
- 洛谷4951 地震 bzoj1816扑克牌 洛谷3199最小圈 / 01分数规划
洛谷4951 地震 #include<iostream> #include<cstdio> #include<algorithm> #define go(i,a,b ...
- 洛谷P2668 斗地主==codevs 4610 斗地主[NOIP 2015 day1 T3]
P2668 斗地主 326通过 2.6K提交 题目提供者洛谷OnlineJudge 标签搜索/枚举NOIp提高组2015 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 出现未知错误是说梗啊 ...
随机推荐
- poj-2420 A Star not a Tree?(模拟退火算法)
题目链接: A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5219 Accepte ...
- linux命令学习笔记(4):mkdir命令
linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限, 并且指定的目录名不能是当前目录中已有的目录. .命令格式: mkdir [选项] 目录... .命令功 ...
- 继续学习C:数字进制表示
1. 数字后面跟D表示十进制,如:123D. 2. 数字后面跟B表示二进制,如:10010B. 3. 数字后面跟Q表示八进制,如:652Q. 4. 数字后面跟H表示十六进制,如:2B5H. 把十进制数 ...
- HihoCoder1338 A Game(记忆化搜索)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a game. There is an integ ...
- 脚本手动执行正常,放cron中执行有问题的原因
问题原因: 1. crond服务没启动 2. 环境变量如 PATH LANG SHELL 等设置不对 3. 脚本中引用的文件地址是相对路径,而非绝对路径. 排查步骤: 以 check ...
- UOJ #348 州区划分 —— 状压DP+子集卷积
题目:http://uoj.ac/problem/348 一开始可以 3^n 子集DP,枚举一种状态的最后一个集合是什么来转移: 设 \( f[s] \) 表示 \( s \) 集合内的点都划分好了, ...
- CCS V5 使用教程二:创建工程和配置软件仿真
新建CCS项目 选择File/New/CCS Project: 新建项目对话框 1) Project name: 指项目名称,这里要注意的项目名称不区分大小写. 2) Ou ...
- 自己写的基于java Annotation(注解)的数据校验框架
JavaEE6中提供了基于java Annotation(注解)的Bean校验框架,Hibernate也有类似的基于Annotation的数据校验功能,我在工作中,产品也经常需要使 用数据校验,为了方 ...
- ruby on rails 环境搭建步骤
1.安装ruby ruby的下载页面一个版本有3样要下载的,帮助文件和安装文件.还有一个mingw. 安装时抛出make出错信息就是由于没有安装mingw引起的 到下载页http://rubyforg ...
- VisualGDB系列4:概述-Linux程序与VS
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文将会阐述如何使用VisualGDB来 ...