HDU 5783 Divide the Sequence(数列划分)
HDU 5783 Divide the Sequence(数列划分)
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description - 题目描述
Alice有一个数列A,她想把A拆分出尽可能多的子串,并且每个子串的任意前缀和都大于0。
CN
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 - 输出
对于每组测试用例,输出此序列的最大划分数。
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(数列划分)的更多相关文章
- HDU 5783 Divide the Sequence (贪心)
Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...
- hdu 5783 Divide the Sequence 贪心
Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...
- HDU 5783 Divide the Sequence
Divide the Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 【贪心】HDU 5783 Divide the Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...
- 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 ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- 2016 Multi-University Training Contest 5 Divide the Sequence
Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- 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区间上的所以数变成 ...
随机推荐
- C# Math
Math.Ceiling 向上进位取整.例如:Math.Ceiling(32.6)=33; Math.Ceiling(32.0)=32; Math.Floor 向下舍位取整.例如:Math.Floor ...
- Docker-compose命令详解
语法: Define and run multi-container applications with Docker. Usage: docker-compose [-f=<arg> ...
- 【转】NGUI研究院之为什么打开界面太慢(十三)
NGUI打开界面太慢了,起初一直以为是unity的问题,最近经过我的全面测试我发现这和unity没有关系.一般一个比较复杂的界面大概需要150个GameObject 或者 UISprite .我用N ...
- IOS移动设备处理器指令集 armv6、armv7、armv7s及arm64
Arm处理器,因为其低功耗和小尺寸而闻名,几乎所有的手机处理器都基于arm,其在嵌入式系统中的应用非常广泛,它的性能在同等功耗产品中也很出色. Armv6.armv7.armv7s.arm64都是ar ...
- MySQL 的 utf8_general_ci 和 utf8_unicode_ci 有什么区别,应如何选择?
一般的解说是 utf8_general_ci 速度较快,utf8_unicode_ci 准确性较好 … 但快在那里,又好在什么地方呢? 首先就其准确性说,这世界上有无数种文字,除了通用的英文使用我们较 ...
- 《30天自制操作系统》14_day_学习笔记
harib11a--harib11c: 继续测试性能:我们在harib10h中进行了定时链表结构的改进“消除了移位处理”.下面我们设定490个定时器(它们都被设定启动50天才超时)来测试一下改进的效果 ...
- Matlab中图片保存的5种方法
matlab的绘图和可视化能力是不用多说的,可以说在业内是家喻户晓的. Matlab提供了丰富的绘图函数,比如ez**系类的简易绘图函数,surf.mesh系类的数值绘图函数等几十个.另外其他专业工具 ...
- JS 删除字符串最后一个字符的几种方法
字符串:string s = "1,2,3,4,5," 目标:删除最后一个 "," 方法:1.用的最多的是Substring,这个也是我一直用的 s=s.Sub ...
- JS中同名函数有效执行顺序
html中如果出现函数同名时:如果有多个外部引入的js文件,例如a.js和b.js(引入顺序假定是a.js,然后是b.js),同时html中本身也有内部的js.那么针对 出现函数名一样的情况时,无论他 ...
- mysql中and和or
and的优先级高于or,所以一个sql语句中如果and和or同时出现,则or要加括号