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. Linux文件与进程的Capability简介

    UID这种权限机制颗粒太粗,容易引起权利过剩(溢出),Linux引入了Capability:每个Capability系统内以一位Bit代表,OS内部使用64bit存储. 下面是android的capa ...

  2. /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found错误的解决

    升级cmake时,提示"Error when bootstrapping CMake:Problem while running initial CMake",第二次运行./boo ...

  3. Windows下搭建Mysql集群

    Mysql集群的基本架构如下: 基本原理参考:[转]MySQL Cluster (集群)基本原理 这里采用最小配置,用两台机器来分别部署一个management 节点,2个data node, 2个s ...

  4. 宏ut_2pow_round

    计算 m的整数倍 不大于n #define ut_2pow_round(n, m) ((n) & ~((m) - 1)) #include <stdio.h>#include &l ...

  5. [swustoj 373] Antiprime数

    Antiprime数(0373) 问题描述 如果一个自然数n(n>=1),满足所有小于n的自然数(>=1)的约数个数都小于n的约数个数,则n是一个Antiprime数.譬如:1, 2, 4 ...

  6. android-async-http

    安装 http://blog.csdn.net/wangwei_cq/article/details/9453345 包内的一些基本的参数 http://www.cnblogs.com/manuose ...

  7. 如何在Asp.Net WebApi接口中,验证请求参数中是否携带token标识!

    [BasicAuthentication] public abstract class ApiControllerBase : ApiController { #region Gloal Proper ...

  8. I.MX6 Ethernet UI patch failed

    /*********************************************************************** * I.MX6 Ethernet UI patch f ...

  9. 漂亮灵活设置的jquery通知提示插件toastr

    toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...

  10. ms_sql:drop and create a job

    /****** Object: Job [syncData_23_00] Script Date: 09/30/2013 16:48:32 ******/ ) IF EXISTS (SELECT jo ...