洛谷P3078 [USACO13MAR]扑克牌型Poker Hands
题目描述
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的更多相关文章
- 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands
P3078 [USACO13MAR]扑克牌型Poker Hands 题目描述 Bessie and her friends are playing a unique version of poker ...
- 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 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 出现未知错误是说梗啊 ...
随机推荐
- codeforces 651B B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- C语言访问MCU寄存器的两种方式
转自http://blog.csdn.net/liming0931/article/details/7752248 单片机的特殊功能寄存器SFR,是SRAM地址已经确定的SRAM单元,在C语言环境下对 ...
- ffmpeg处理rtmp/文件/rtsp的推流和拉流
ffmpeg处理rtmp/文件/rtsp的推流和拉流 本demo演示了利用ffmpeg从服务器拉流或本地文件读取流,更改流url或文件类型名称发送回服务器或存到本地的作用. 由于本程序只写了3个小 ...
- bzoj1067降雨量
True和False都好搞 Maybe的情况: 1.Y年和X年的降雨量已知,X年的降雨量不超过Y年的降雨量,从Y+1到X-1年中存在至少一年的降雨量未知,从Y+1到X-1年中已知的降雨量都小于X年的降 ...
- L2-016 愿天下有情人都是失散多年的兄妹(25 分)
呵呵.大家都知道五服以内不得通婚,即两个人最近的共同祖先如果在五代以内(即本人.父母.祖父母.曾祖父母.高祖父母)则不可通婚.本题就请你帮助一对有情人判断一下,他们究竟是否可以成婚? 输入格式: 输入 ...
- 从python2,python3编码问题引伸出的通用编码原理解释
今天使用python2编码时遇到这样一条异常UnicodeDecodeError: ‘ascii’ code can’t decode byte 0xef 发现是编码问题,但是平常在python3中几 ...
- mysql du-master配置
db-server1 my.cnf log_bin = mysql-binbinlog_format = mixedserver_id = 1 read-only = 0#binlog-do-db = ...
- POJ3256:Cow Picnic
Cow Picnic Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5432 Accepted: 2243 Descri ...
- mongodb 的命令操作(转)
成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show collections:显 ...
- cmake opencv,dlib 编译静态库 1
无论windows,linux 所有的库 ,dlib,opencv 通过cmake-gui 设置好静态库, 动态库,和其他各个选项 Tips: cmake 优先级用cmake-gui,因为命令太多,容 ...