洛谷 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 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 出现未知错误是说梗啊 ...
随机推荐
- Hotel booking(spfa+floyd)
http://acm.hdu.edu.cn/showproblem.php?pid=2992 题意:有n个城市,编号为(1~n),有一些城市中有一些旅店,要求从一个城市到另一个城市不能超过10小时,问 ...
- 苹果树(线段树+Dfs序)
1228 苹果树 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在卡卡的房子外面,有一棵苹果树.每年的春天,树上总 ...
- [Swift通天遁地]九、拔剑吧-(13)创建页面的景深视差滚动效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Codeforces 718C 线段树+矩乘
题意: 维护一个序列,支持两种操作:1.区间[l,r]的权值+x2.询问区间[l,r]的函数和,即∑fib(x)这里的函数即斐波那契函数数据范围:1≤n,q≤105 思路:一般求斐波那契函数的方法可以 ...
- 【BZOJ3960】DZY Loves Math V(数论)
题目: BZOJ3560 分析: orz跳瓜. 欧拉函数的公式: \[\phi(n)=n(\prod \frac{p_i-1}{p_i})\] 其中 \(p_i\) 取遍 \(n\) 的所有质因子. ...
- viewDidUnload,viewDidLoad,viewWillAppear,viewWillDisappear的作用以及区别
viewDidLoad:在视图加载后被调用 viewWillAppear:视图即将可见时调用.默认情况下不执行任何操作 viewDidAppear: 视图已完全过渡到屏幕上时调用 viewWillDi ...
- gerrit项目配置
1. 相关约定说明: 1.1 gerrit服务器ip地址:192.168.130.10 1.2 gerrit服务器端用户名:gerrit 1.3 gerrit用户端管理员:admin 1.4 ssh端 ...
- 使用xml实现的增删改查功能
实体类: package vo; public class Contact { private String id; private String name; private String gende ...
- 170925_2 Python socket 创建UDP的服务器端和客户端
[python版本]3.6 UDP服务器端: from socket import * from time import ctime host = '' port = 21567 buf_size = ...
- Zabbix 监控磁盘IO
Zabbix 监控磁盘IO 1.数据获取脚本 #!/bin/bash # resource: http://www.muck.net/19/getting-hard-disk-performance- ...