Divide the Sequence

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5783

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

Source

2016 Multi-University Training Contest 5

##题意:

将数串A分解成尽可能多的字串,使得每个字串的任一前缀和都不小于零.


##题解:

贪心.
从后往前遍历,每个和为零的地方都可以分割一次.
注意用longlong.


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 1010000
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;

int n;

LL num[maxn];

int main(int argc, char const *argv[])

{

//IN;

//int t; cin >> t;
while(scanf("%d", &n) != EOF)
{
for(int i=1; i<=n; i++)
scanf("%I64d", &num[i]); LL cur = 0;
int ans = 0;
for(int i=n; i>=1; i--) {
cur += num[i];
if(cur >=0) {
ans++;
cur = 0;
}
} printf("%d\n", ans);
} return 0;

}

HDU 5783 Divide the Sequence (贪心)的更多相关文章

  1. hdu 5783 Divide the Sequence 贪心

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

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

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

  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

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

  5. 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 ...

  6. Divide the Sequence (贪心)

    题意:求将一串数据尽可能多分成所有前缀和大于0的连续子串. 思路:由于是要求所有前缀和大于0,那么只要从后往前推就好了. #include<bits/stdc++.h> using nam ...

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

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

  8. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  9. HDU5014Number Sequence(贪心)

    HDU5014Number Sequence(贪心) 题目链接 题目大意: 给出n,然后给出一个数字串,长度为n + 1, 范围在[0, n - 1].然后要求你找出另外一个序列B,满足上述的要求,而 ...

随机推荐

  1. Java中boolean型变量的默认值问题

    1.首先分析Java中的三种不同变量的区别,如下表所示   概念 默认值 其他 类变量 也叫静态变量,是类中独立于方法之外的变量 用static 修饰 有默认初始值,系统自动初始化. 如boolean ...

  2. bat拷贝文件

    最近在部署服务器的时候,需要用到把一个站点文件拷贝到其他站点.一个一个手动copy太累人了,写了个简单的批处理文件,基本能达到目的,具体怎么做呢: 1.把需要拷贝到各个站点的文件,单独放到一个目录下. ...

  3. Android权限安全(10)应用与设备绑定

    有些时候开发者想要把应用与设备绑定 如: 计费应用下载,防导出运行. app内部注册付费等等. 常用的绑定方案:

  4. string.length()与-1比较为什么会出现匪夷所思的结果

    今天调试程序发现了个匪夷所思的事情,-1与string.length()比较永远是-1大,看下面代码 #include<iostream> #include<string> u ...

  5. maven - setting.xml

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  6. Android自动化测试之Monkeyrunner从零开始(三)

    转自http://www.51testing.com/html/81/22381-854342.html 时光过得太快了,一晃离上一篇monkeyrunner系列的博客已经一年多了.这一年多时间经历了 ...

  7. bzoj1296: [SCOI2009]粉刷匠

    dp. 用到俩次dp,用1和0代表俩种颜色,首先对于每块木板我们进行一次dp,g[i][j]代表前j个格子刷i次最多能涂到几个格子. 则 g[i][j]=max(g[i-1][k],max(cnt[j ...

  8. bzoj2561: 最小生成树

    如果出现在最小生成树上,那么此时比该边权值小的边无法连通uv.据此跑最小割(最大流)即可. #include<cstdio> #include<cstring> #includ ...

  9. Oracle中使用escape关键字实现like匹配特殊字符,以及&字符的转义

    转:http://blog.chinaunix.net/uid-26896647-id-3433968.html 问题描述:如果在一个表中的一个字段上存在'&',  '_',  '%'这样的特 ...

  10. "xxxx".zip:这个压缩文件格式未知或者数据已经被损坏,打不开压缩文件,总出现这个提示的解决方法

    从网上下载了一些压缩文件,有时解压时会出现“这个压缩文件格式未知或者数据已经被损坏”或“未找到压缩文件”的提示. 造成的原因有两种: 一.网站上的压缩文件本来就是坏的. 1.你可以尝试可以使用WINR ...