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.

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.

多组测试用例。
每组测试用例的第一行为一个整数n。
下一行有n个整数A1,A2⋯An。
≤n≤1e6
−≤A[i]≤
你可以认为不存在无解的情况。

CN

Output - 输出

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

CN

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

题解

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

1
1 2
1 2 3

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

代码 C++

 #include <cstdio>
__int64 data[];
int main(){
__int64 n, i, opt, tmp;
while (~scanf("%I64d", &n)){
for (i = opt = tmp = ; i < n; ++i) scanf("%I64d", data + i);
for (--i; ~i; --i){
tmp += data[i];
if (tmp >= ) tmp = , ++opt;
}
printf("%I64d\n", opt);
}
return ;
}

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. C#抽象类、抽象方法、虚方法

    定义抽象类和抽象方法: abstract 抽象类特点: 1.不能初始化的类被叫做抽象类,它们只提供部分实现,但是另一个类可以继承它并且能创建它们的实例 2.一个抽象类可以包含抽象和非抽象方法,当一个类 ...

  2. iOS 3D touch 使用技巧

    第一个 在桌面中3d Touch 打开菜单 由于本人纯属代码党,本次实现方法也只使用代码实现 到达到这个效果并不难,只需要在appdelegate中实现以下代码即可 ,当然也有缺点,就是这个app没运 ...

  3. JS中的_proto_

    var grandfather = function(){ this.name = "LiuYashion" ; } var father = function(){}; fath ...

  4. oracle从零开始学习笔记

    查询现有数据库:select name from V$database; 解锁用户scott:alter user scott account unlock; 普通用户连接:conn scott 默认 ...

  5. IE localhost 不能解析

    新建的项目  在虚拟机里试了,虚拟机的IE可以解析.本机的360.谷歌都可以解析 只有IE不可以,我把IE11卸载了换成IE8也不行.再换回IE11还是不行 在网上找了很多方法 最后  看到有一个人 ...

  6. navicat----------局域网数据库:如何让navicat链接局域网其他的数据库。

    1.方法很简单了,找到被链接的数据库,打开以后有一个自带的mysql数据库,打开以后下面有一个user表,把里面的第一条数据的第一个字段改成% 百分号,然后保存,重启服务器,搞定 2.如果是linux ...

  7. input内强制保留小数点后两位 位数不足时自动补0

    input内强制保留小数点后两位 位数不足时自动补0 小数点后位数超出2位时进行四舍五入 需引入jquery包 1.11.2版本 1 function xiaoshu(x) 2 { 3 var f = ...

  8. 借助Glances Monitor,密切关注你的系统

    两种方法安装 glances 通常可以有两种方法安装 glances.第一种是通过编译源代码的方式,这种方法比较复杂另外可能会遇到软件包依赖性问题.还有一种是使用特定的软件包管理工具来安装 glanc ...

  9. 1.Cookie的定义和分类,及优缺点

    定义:用户请求网页,连接服务器,服务器在用户机上寻找属于它的cookie文件,如果有,就读取它的信息,如果没有就创建一个cookie文件发送给用户,存储在本地,用户可以通过浏览器选项设置是否接收服务器 ...

  10. 在linux中安装adb和fastboot工具

    我用的是archlinux,在官方的软件仓库里就可以找到对应的包,包的名字叫:android-tools 据说debian系列的软件包是两个,分别是:android-tools-adb, androi ...