题目描述

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. codeforces 707B B. Bakery(水题)

    题目链接: B. Bakery 题意: 是否存在一条连接特殊和不特殊的边,存在最小值是多少; 思路: 扫一遍所有边: AC代码: #include <iostream> #include ...

  2. 转载 解决Android与服务器交互大容量数据问题

    对于目前的状况来说,移动终端的网络状况没有PC网络状况那么理想.在一个Android应用中,如果需要接收来自服务器的大容量数据,那么就不得不考虑客户的流量问题.本文根据笔者的一个项目实战经验出发,解决 ...

  3. 卸载DCOS

    再次安装,已经是隔了两天,我打算换一台机器作为boot机器,但是发现报错,告知部署设备已经安装了dcos:看来需要卸载:uninstall-master.sh /opt/mesosphere/bin/ ...

  4. shell入门-awk-1

    awk对于sed grep的优势在于分段,把分隔符分割成一小段一小段,针对段进行匹配,替换,操作,逻辑判断,比较...等 awk的基本操作 [root@wangshaojun ~]# awk -F ' ...

  5. File 类 操作实例

    File 操作 <介绍> 尽管java.io定义的大多数类是实行流式操作的,File类不是.它直接处理文件和文件系统.也就是说,File类没有指定信息怎样从文件读取或向文件存储:它描述了文 ...

  6. <table>的使用以及确定取消按钮的设置

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Angular09 数据绑定、响应式编程、管道

    1 数据绑定的分类 1.1 单向数据绑定 1.1.1 属性绑定 -> 数据从组件控制类到组件模板 DOM属性绑定 HTML属性绑定 1.1.2 事件绑定 -> 数据从组件模板到组件控制类 ...

  8. Some of your uncommitted changes would be overwritten by syncing.Please commit your changes then try

    解决方法有三种,在GitHub shel中输入以下命令,任选一种方法就能解决问题 git reset --hard HEAD -- Destructive. When you do this you' ...

  9. 13、ubuntu终端快捷键(参考 dy9776)

    1.终端的快捷键 Tab 自动补全 Ctrl+a 光标移动到开始位置 Ctrl+e 光标移动到最末尾 Ctrl+l 相当于clear,即清屏 Ctrl+Z 把当前任务放到后台运行(相当于运行命令时后面 ...

  10. Qt Console Application

    代码编译完生成的.o文件(又称对象文件,是可执行文件)和链接.o文件形成的.exe可执行文件都保存在“build-Project-Desktop_Qt_5_8_0_GCC_64bit-Debug”中. ...