题目描述

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;
}

最新文章

  1. Framework4.5语法糖 异步Task
  2. Backbone源码解析(二):Model(模型)模块
  3. Log4Net指南
  4. word2010中怎样快速修改同级标题格式
  5. Eclipse中创建标准web工程以及标准目录结构说明
  6. Linux 按行分割文件(转载)
  7. EXPORT_SYMBOL的作用是什么
  8. 除了修改WEBCONFIG会导致WEB服务重启外,还有其他的什么操作会导致重启?
  9. 关于Eclipse启动报错,jvm版本不匹配的问题
  10. 【swift-总结】函数
  11. Java面试大纲-java面试该做哪些准备,java开发达到这样的水平可以涨工资
  12. php 日期时间类型带毫秒
  13. wayne生产环境部署(360的容器发布平台-开源)
  14. 占位 Bootstrap
  15. Python 深浅copy 和文件操作
  16. iOSApp上下有黑边
  17. python自动化之PDF
  18. IntelliJ IDEA 创建Java Web项目
  19. rem的计算
  20. oracle 所有 hint(转)

热门文章

  1. html中Meta属性
  2. the referenced script on this behaviour is missing!
  3. C语言访问MCU寄存器的两种方式
  4. oracle rac的特征
  5. bash批量处理
  6. poj 2105 IP Address(水题)
  7. css中的块级和内联元素
  8. Linker Tools Error LNK2001
  9. javaScript之事件处理程序
  10. ueditor1.4.3jsp版在上传图片报&quot;未找到上传文件&quot;解决方案