洛谷 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 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 出现未知错误是说梗啊 ...
随机推荐
- E20170709-hm
scrape vt. 擦,刮; 擦去; 擦伤,刮破; 挖空;
- [Swift通天遁地]六、智能布局-(5)给视图添加Align(对齐)和Fill(填充的约束以及Label的约束
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Java Itext 生成PDF文件
利用Java Itext生成PDF文件并导出,实现效果如下: PDFUtil.java package com.jeeplus.modules.order.util; import java.io.O ...
- PHP入门开发
1.下载开发工具phpstorm 地址:http://www.jetbrains.com/phpstorm/download/download-thanks.html?platform=windows ...
- cloudera-scm-server启动时出现Caused by: java.io.FileNotFoundException: /var/lib/cloudera-scm-server/.keystore (No such file or directory)问题解决方法(图文详解)
不多说,直接上干货! 问题详情 查看/var/log/cloudera-scm-server.log的启动日志 问题来源 我在用cloudermanager安装好之后,然后,在对如下. 配置kerbe ...
- SQL Server语言 函数以及SQL编程
1.数学函数:操作一个数据,返回一个结果 --去上限: ceiling ☆select ceiling(price) from car --去下限:floor ☆select floor(price) ...
- C#学习-程序集和反射
准备项目 1.新建一个空的解决方案MyProj.sln 2.在该解决方案下,建一个控制台项目P01.csproj 3.在该项目下,自己新建一个类MyFirstClass.cs 查看解决方案MyProj ...
- Java—将文件夹压缩为zip文件
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java ...
- SAS学习笔记之《SAS编程与数据挖掘商业案例》(5)SAS宏语言、SQL过程
SAS学习笔记之<SAS编程与数据挖掘商业案例>(5)SAS宏语言.SQL过程 1. 一个SAS程序可能包含一个或几个语言成分: DATA步或PROC步 全程语句 SAS组件语言(SCL) ...
- Android:用签名打包后微信分享失效
刚开始使用微信分享,申请的微信appid也可以在直接使用,分享成功! 当我使用自己的签名打包分享时却分享失败,一闪而过,好郁闷的说,为什么之前没有打包就可以,签名打包后就不可以了... 开始查找各种资 ...