题目描述

Bessie and her friends are playing a unique version of poker involving a deck with N (1 <= N <= 100,000) 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 <= a_i <= 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.

思路:贪心即可。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long long ans,x,pre;
int main(){
scanf("%d%lld",&n,&x);
ans+=x;pre=x;
for(int i=;i<=n;i++){
scanf("%lld",&x);
if(x>pre) ans+=x-pre;
pre=x;
}
cout<<ans;
}

洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands的更多相关文章

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

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

  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. Ruby Range类

    创建: 2017/09/30    

  2. 9.2NOIP模拟题

    9.2 NOIP模拟 题目名称 “与” 小象涂色 行动!行动! 输入文件 and.in elephant.in move.in 输出文件 and.out elephant.in move.in 时间限 ...

  3. [Swift通天遁地]三、手势与图表-(8)制作股市中常用的蜡烛图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. 数据库得到too many connections”错误信息

    查进程  show processlist删除进程  kill ID查完整sql  show full processlist; 连数据库   MySQL -S /tmp/mysql.sock   或 ...

  5. 使用UDEV SCSI规则在Oracle Linux上配置ASM

    对于使用ASM管理的磁盘来说,需要一种能够用于一致性标识磁盘设备及其正确的所属关系和权限的手段.在Linux系统中,可以使用ASMLib来执行这项任务,但是这样做的缺点是在操作系统上增加了额外的一层, ...

  6. hdu3535题解

    hdu3535:http://acm.hdu.edu.cn/showproblem.php?pid=3535 该题是非常全面的一道分组背包问题.其实理解了最多一个的分组背包问题,解题起来也是很简单的. ...

  7. html——细线表格

    细线: 1.table表格设置背景色 2.table中设置单元格距离 3.tr标签设置另外一种背景色 <!DOCTYPE html> <html> <head lang= ...

  8. 【译】x86程序员手册04 - 2.2数据类型

    2.2 Data Types 数据类型 Bytes, words, and doublewords are the fundamental data types (refer to Figure 2- ...

  9. JavaScript定时器及其他

    By Abyssly Jun 20 2014 Updated:Jun 20 2014 平时工作中不可避免地要嵌套网页,对JavaScript的深入了解还是很有必要滴.而JavaScript中一个容易让 ...

  10. tac

    功能说明:反向显示文件内容. 参数选项: -b 在行前而非行尾加分隔标志. -r 将分隔标志视作正则表达式来解析. -s 使用指定字符串代替换行作为分隔标志.   cat命令与tac命令的对比: