Divide the Sequence (贪心)
题意:求将一串数据尽可能多分成所有前缀和大于0的连续子串。
思路:由于是要求所有前缀和大于0,那么只要从后往前推就好了。
#include<bits/stdc++.h>
using namespace std; const int maxn = 1e6 + ;
long long arr[maxn], n; int main(){
while(~scanf("%d", &n)){
for(int i = ; i < n; i ++) scanf("%lld", &arr[i]);
int ans = ;
long long sum = ;
for(int i = n - ; i >= ; i --) {
sum += arr[i];
if(sum >= ){
ans ++;
sum = ;
}
}
printf("%d\n",ans);
}
return ;
}
Divide the Sequence (贪心)的更多相关文章
- hdu 5783 Divide the Sequence 贪心
Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...
- HDU 5783 Divide the Sequence (贪心)
Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5783 Divide the Sequence
Divide the Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 2016 Multi-University Training Contest 5 Divide the Sequence
Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...
- HDU5014Number Sequence(贪心)
HDU5014Number Sequence(贪心) 题目链接 题目大意: 给出n,然后给出一个数字串,长度为n + 1, 范围在[0, n - 1].然后要求你找出另外一个序列B,满足上述的要求,而 ...
- 【题解】Cut the Sequence(贪心区间覆盖)
[题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ...
- 【贪心】HDU 5783 Divide the Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...
- [HDOJ5783]Divide the Sequence(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783 题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0. 从后往前截取,这样不会影 ...
随机推荐
- Golang语言下使用Protocol Buffer教程
代码仓库地址 一.介绍 Protobuf是Google旗下的一款平台无关,语言无关,可扩展的序列化结构数据格式.所以很适合用做数据存储和作为不同应用,不同语言之间相互通信的数据交换格式,只要实现相同的 ...
- Javadoc转换chm帮助文档的四种方法总结
1) 将现有的 html 文件集(比如 api) 制作成chm 文档 http://www.blogjava.net/lishunli/archive/2010/01/07/308618.html 我 ...
- spark StructType的应用,用在处理mongoDB keyvalue
近期在处理mongoDB 数据的时候,遇到了非常奇怪的格式,账号密码的日志都追加在一条记录里面,要取一个密码的时长和所有密码的平均时长就非常繁琐. 用了各种迭代计算,非常困难,而且printschem ...
- laravel5.8笔记七:语言包
语言包控制config/app.php 'locale' => 'en', 语言包位置:resources/lang/cn/ 建立resources/lang/cn/common.php < ...
- git log --pretty=format:" "
控制显示的记录格式,常用的格式占位符写法及其代表的意义如下: 选项 说明%H 提交对象(commit)的完整哈希字串%h 提交对象的简短哈希字串%T 树对象(tree)的完整哈希字串% ...
- 下载Crypto,CyCrypto,PyCryptodome 报错问题
python下载Crypto,CyCrypto,PyCryptodome,如有site-packages中存在crypto.pycrypto,在pip之前,需要pip3 uninstall crypt ...
- ArcGIS 10.3 AddIN编译旧版本项目问题
ArcGIS 10.1的AddIN项目,后来ArcGIS版本升级为10.3 AddIN项目想做一些细节调整,结果出生成时没有生成esriaddin文件,ArcMap中AddIn Manager中也没有 ...
- Oracle课程档案,第十天
用户管理 Authentication: 身份验证 AAA:Authentication: 身份验证 Authorization: 权限管理 Audition: 审计 grant:授权 unset:撤 ...
- Python学习之旅(三十)
Python基础知识(29):virtualenv virtualenv:用来为一个应用创建一套隔离的Python运行环境 比如,现有两个Python项目,一个是Python2.7的一个是Python ...
- smartFloat
$.fn.smartFloat = function() { var position = function(element) { var top = element.posi ...