题目描述

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的更多相关文章

  1. 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands

    P3078 [USACO13MAR]扑克牌型Poker Hands 题目描述 Bessie and her friends are playing a unique version of poker ...

  2. P3078 [USACO13MAR]扑克牌型Poker Hands

    题目描述 Bessie and her friends are playing a unique version of poker involving a deck with N (1 <= N ...

  3. 「Luogu P3078 [USACO13MAR]扑克牌型Poker Hands」

    本题有\(O(N)\)的优秀做法,但是因为在考场上不一定能想到,就来分享一种\(O(N\log_2N)\)的做法.虽然有点慢,但是可以过. 前置芝士 线段树:提高组及以上必备内容,不会的同学可以学习一 ...

  4. 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands

    看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...

  5. 洛谷P3080 [USACO13MAR]牛跑The Cow Run

    P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his ...

  6. 洛谷 P3079 [USACO13MAR]农场的画Farm Painting

    P3079 [USACO13MAR]农场的画Farm Painting 题目描述 After several harsh winters, Farmer John has decided it is ...

  7. 洛谷2014选课(树型dp)

    题目:https://www.luogu.org/problemnew/show/P2014 千万注意遍历 j 和 k 的边界! 0点很好用. siz很好用. #include<iostream ...

  8. 洛谷4951 地震 bzoj1816扑克牌 洛谷3199最小圈 / 01分数规划

    洛谷4951 地震 #include<iostream> #include<cstdio> #include<algorithm> #define go(i,a,b ...

  9. 洛谷P2668 斗地主==codevs 4610 斗地主[NOIP 2015 day1 T3]

    P2668 斗地主 326通过 2.6K提交 题目提供者洛谷OnlineJudge 标签搜索/枚举NOIp提高组2015 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 出现未知错误是说梗啊 ...

随机推荐

  1. bzoj1208Splay

    Splay查前驱后继 小tips:在bzoj上while(scanf)这种东西可以让程序多组数据一起跑 反正没加我就t了 #include<cstdio> #include<iost ...

  2. 20179203 《Linux内核原理与分析》第十周作业

    第17章 设备与模块 一.设备类型 1. Linux及Unix系统: 块设备 字符设备 网络设备 2.块设备: 通常缩写为blkdev,它是可寻址的,寻址以块为单位,块大小随设备不同而不同:块设备通常 ...

  3. 多版本Python共存时pip给指定版本的python安装package的方法

    在Linux安装了多版本Python时(例如python2.7和3.6),pip安装的包不一定是用户想要的位置,此时可以用 -t 选项来指定位置. 例如目标位置是/usr/local/lib/pyth ...

  4. Bootstrap CSS教程

    Bootstrap 教程 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加 ...

  5. JS上传图片-通过FileReader获取图片的base64

    下面文章,我想要的是: FileReader这个对象,可以借助FileReader来获取上传图片的base64,就可以在客户端显示该图片了.同时,还可以把该图片的base64发送到服务端,保存起来. ...

  6. 如何得到DataTable的列名

    foreach (DataColumn dc in dtfood.Columns) { string lm = dc.ColumnName; }

  7. HDOJ1015(简单深搜)

    Safecracker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. 十二:JAVA I/O

     输入模式                                                          输出模式 ⑴字节输入流:InputStream ⑵字节输出流:Output ...

  9. PID控制及整定算法

    一.PID控制算法 PID是比例.积分.微分的简称,PID控制的难点不是编程,而是控制器的参数整定.参数整定的关键是正确地理解各参数的物理意义,PID 控制的原理可以用人对炉温的手动控制来理解.阅读本 ...

  10. SpringMVC 利用@ResponseBody注解返回Json时,出现406 not acceptable 错误的解决方法。

    1 在RequestMapping中加入produces属性如: @RequestMap(value="/path",produces="application/json ...