洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述
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.
输入输出样例
说明
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的更多相关文章
- 洛谷P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述 Bessie and her friends are playing a unique version of poker involving a deck with \(N\) (\(1 \ ...
- 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 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 出现未知错误是说梗啊 ...
随机推荐
- mysql的启动和停止
1.检查数据库服务器是否开启:任务管理器-->后台进程-->查看mysqld是否存在.存在说明开启了,反之没开启 2.管理员运行cmd,输入重启指令:net start **(**数据库名 ...
- E20170805-hm
mechanize vt. 使机械化; 用机械装置;
- ural 1012. K-based Numbers. Version 2(大数dp)
和1009相同,只是n达到了180位,可以模拟大数加和大数乘,这里用的java中的大数. import java.math.BigInteger; import java.util.Scanner; ...
- 洛谷P1726 上白泽慧音(Tarjan强连通分量)
P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...
- [App Store Connect帮助]三、管理 App 和版本(2.3)输入 App 信息:提供自定许可协议
Apple 提供了适用于所有地区的标准 EULA(最终用户许可协议).如果您不提供自定许可协议,则您的 App 会应用标准 Apple EULA,且该许可协议链接不会显示在您的 App Store 产 ...
- Comet OJ - Contest #3 题解
传送门 太菜了连\(D\)都做不出来没有小裙子\(QAQ\) \(A\) 暴力把所有的数对都算出来,然后\(sort\)一下就行了 const int N=505; int a[N],st[N*N], ...
- 【知识总结】卡特兰数 (Catalan Number) 公式的推导
卡特兰数的英文维基讲得非常全面,强烈建议阅读! Catalan number - Wikipedia (本文中图片也来源于这个页面) 由于本人太菜,这里只选取其中两个公式进行总结. (似乎就是这两个比 ...
- android sqlite中判断某个表是否存在
<span style="font-size:18px;">sqlite 中判断某个表是否存在的方法,贴出来供大家参考 /** * 判断某张表是否存在 * @param ...
- [ NOIP 2009 ] TG
\(\\\) \(\#A\) \(Spy\) 给出两个长度均为\(N\)相同的样例串,建立第一个串各个字符向第二个串对应位置字符的映射,并用映射转换给出的长度为\(M\)第三个串,输入保证只有大写字符 ...
- Android视频截图
本文介绍如何获取视频中某个时间点的数据 调用以下方法即可,特别注意,在获取图片时的参数单位为微秒,不是毫秒 如果错用了毫秒会一直获取第一帧的画面 /** * 获取某个时间点的帧图片 * * @para ...