Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2232    Accepted Submission(s): 628

Problem Description
Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not small than 0.
 
Input
The input consists of multiple test cases. 
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2⋯An.
1≤n≤1e6
−10000≤A[i]≤10000
You can assume that there is at least one solution.
 
Output
For each test case, output an integer indicates the maximum number of sequence division.
 
Sample Input
6
1 2 3 4 5 6
4
1 2 -3 0
5
0 0 0 0 0
 
Sample Output
6
2
5

题意:

给定一串数字分成若干份,使任意份的任意前缀和都不为负。

从后向前遍历贪心。

附AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int a[]; int main(){
int n;
while(~scanf("%d",&n)){
int sum=n-;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
int t=;
while(sum>=){
long long ans=;
ans+=a[sum];
while(ans<){
sum--;
ans+=a[sum];
}
t++;
sum--;
}
printf("%I64d\n",t);
}
return ;
}

Divide the Sequence的更多相关文章

  1. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. 2016 Multi-University Training Contest 5 Divide the Sequence

    Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...

  3. HDU 5783 Divide the Sequence

    Divide the Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  4. HDU 5783 Divide the Sequence (贪心)

    Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...

  5. hdu 5783 Divide the Sequence 贪心

    Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...

  6. HDU 5783 Divide the Sequence (训练题002 B)

    Description Alice has a sequence A, She wants to split A into as much as possible continuous subsequ ...

  7. [HDOJ5783]Divide the Sequence(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783 题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0. 从后往前截取,这样不会影 ...

  8. HDU-5783 Divide the Sequence(贪心)

    题目大意:给一个整数序列,将其划分成若干个子连续序列,使其每个子序列的前缀和不为负.求最大的划分个数. 题目分析:从后往做累加计算,如果不为负,则计数加一,累加和清0.否则,一直往前扫描.如果最终的和 ...

  9. 【贪心】HDU 5783 Divide the Sequence

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...

随机推荐

  1. Mecanim动画编辑器 - 加入动画层实现并行动作

    1.创建新的状态层 a) 通过下图的1button创建一个新的层   b) 通过下图2属性设置图层的权重.假设为0,则该图层的状态不会影响到总的状态机  c) Mask是设置动画的Avatar的关联节 ...

  2. 前端高频面试题 JavaScript篇

    以下问题都来自于互联网前端面经分享,回答为笔者通过查阅资料加上自身理解总结,不保证解答的准确性,有兴趣讨论的同学可以留言或者私信讨论. 1.JS的异步机制? 2.闭包如何实现? 3.原型链.继承? 4 ...

  3. Error: cannot call methods on draggable prior to initialization; attempted to call

    cannot call methods on draggable prior to initialization; attempted to call  报这个问题的根本原因是由于你的引用文件有问题 ...

  4. 生活娱乐 Wifi机器人的制作流程

    思路简单,但是创意无限~~ 动手能力超强 牛人教你做Wifi机器人(图) 一.前言 Wifi机器人(Wifi Robot):其实是一辆能通过互联网,或500米以外的笔记本无线设施来远程控制的遥控汽车. ...

  5. Yii 清理缓存

    html: <button onclick="clearCache()">ClearCache</button> js: function clearCac ...

  6. phpExcel大数据量情况下内存溢出解决

    版本:1.7.6+ 在不进行特殊设置的情况下,phpExcel将读取的单元格信息保存在内存中,我们可以通过 PHPExcel_Settings::setCacheStorageMethod() 来设置 ...

  7. spring中构造函数注入

    spring中构造函数注入,简单来说,就是通过beans.xml中,设置对应的值.而且通过bean类中的构造函数进行注入这些值. 文件结构 watermark/2/text/aHR0cDovL2Jsb ...

  8. (转)OutOfMemory时抓取heap 快照

    转自:https://testerhome.com/topics/579 首先说一下,在程序没有崩溃的时候如何抓取heap快照.这个大家应该都知道,在ddms中自带此功能.   见上图首先我们选中一个 ...

  9. jvm 调优(2)垃圾回收算法

    可以从不同的的角度去划分垃圾回收算法: 按照基本回收策略分 引用计数(Reference Counting): 比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数. ...

  10. What is the difference between message queue pattern and publish-subscribe?

    What is the difference between message queue pattern and publish-subscribe? - Quora https://www.quor ...