HDU 5783 Divide the Sequence(数列划分)

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

 

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.

  1. Alice有一个数列A,她想把A拆分出尽可能多的子串,并且每个子串的任意前缀和都大于0

CN

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.

  1. 多组测试用例。
  2. 每组测试用例的第一行为一个整数n
  3. 下一行有n个整数A1,A2An
  4. n1e6
  5. −≤A[i]≤
  6. 你可以认为不存在无解的情况。

CN

Output - 输出

For each test case, output an integer indicates the maximum number of sequence division.
  1. 对于每组测试用例,输出此序列的最大划分数。

CN

Sample Input - 输入样例

  1. 6
  2. 1 2 3 4 5 6
  3. 4
  4. 1 2 -3 0
  5. 5
  6. 0 0 0 0 0

Sample Output - 输出样例

  1. 6
  2. 2
  3. 5

题解

  贪心,一开始看错题目了,一直想不出解法,浪费了巨多时间……
  某子串1 2 3的所有前缀为

  1. 1
  2. 1 2
  3. 1 2 3

  显然如果出现负数的话,需要前面的正数来凑,反正无法满足条件。
  做法就是从后往前扫描,记录临时的后n项和,>=0则清空,划分数+1。
  极限数据应该是5e5 * 10000 = 5e9,单纯的int会超,需要__int64。

代码 C++

  1. #include <cstdio>
  2. __int64 data[];
  3. int main(){
  4. __int64 n, i, opt, tmp;
  5. while (~scanf("%I64d", &n)){
  6. for (i = opt = tmp = ; i < n; ++i) scanf("%I64d", data + i);
  7. for (--i; ~i; --i){
  8. tmp += data[i];
  9. if (tmp >= ) tmp = , ++opt;
  10. }
  11. printf("%I64d\n", opt);
  12. }
  13. return ;
  14. }

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 贪心

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

  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. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  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. hdu 4893 Wow! Such Sequence!(线段树)

    题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...

随机推荐

  1. 【转】在sqlserver下增加MYSQL的链接服务器,实现分布式数据库开发第一步

    首先要在SQLserver上服务器上这装ODBC对mysql的支持,我下载了mysql-connector-odbc-5.1.5-win32.rar,安装后在ODBC中有了DRIVER={MySQL ...

  2. 【iCore3 双核心板】iCore3封装库及使用说明V1.0

    iCore3封装库及使用说明下载链接: http://pan.baidu.com/s/1pLq23Qb iCore3 购买链接: https://item.taobao.com/item.htm?id ...

  3. itertools 介绍

    在python中itertool为python提供一系列迭代iterator的方法. 第一个:组合 排列 itertools.combinations(sq, r) 该函数的作用是在列表sq中穷举所有 ...

  4. 多维数组问题 int (*a)[] int []

    今天做调整方阵这道题: 第一遍提交没有通过, 又gdb 重新温故了 交换二维数组中的两行数据: void swap(int *a, int *b) { int t = *a; *a = *b; *b ...

  5. iOS CAShapeLayer记录

    基本知识 看看官方说明: /* The shape layer draws a cubic Bezier spline in its coordinate space. * * The spline ...

  6. SQLSERVER2012 附加数据库重名的问题

    SQL2012附加数据库时如何更改数据库名称呢 方法一: 在“附加为”那一栏填写新的数据库名称就可以 方法二: 使用脚本 附加时点击脚本会自动生成附加脚本 直接修改database的名称即可!

  7. 基于netty的心跳机制实现

    前言:在实现过程查找过许多资料,各种波折,最后综合多篇文章最终实现并上线使用.为了减少大家踩坑的时间,所以写了本文,希望有用.对于实现过程中有用的参考资料直接放上链接,可能有些内容相对冗余,不过时间允 ...

  8. 使用CMD命令设置IP

    使用CMD命令设置IP,将下面文本保存为bat文件后执行 netsh interface ip set address name="本地连接" source=static addr ...

  9. SqlServer数据库端口默认是1433吗?

    1433端口,是SQL Server默认的端口,SQL Server服务使用两个端口:TCP-1433.UDP-1434.其中1433用于供SQL Server对外提供服务,1434用于向请求者返回S ...

  10. 网页中调用Google地图

    <html> <head>  <meta http-equiv="Content-Type" content="text/html; cha ...