Divide the Sequence
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2232 Accepted Submission(s): 628Problem DescriptionAlice 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.InputThe 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.OutputFor each test case, output an integer indicates the maximum number of sequence division.Sample Input6
1 2 3 4 5 6
4
1 2 -3 0
5
0 0 0 0 0Sample Output6
2
5
题意:
给定一串数字分成若干份,使任意份的任意前缀和都不为负。
从后向前遍历贪心。
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int a[]; int main(){
int n;
while(~scanf("%d",&n)){
int sum=n-;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
int t=;
while(sum>=){
long long ans=;
ans+=a[sum];
while(ans<){
sum--;
ans+=a[sum];
}
t++;
sum--;
}
printf("%I64d\n",t);
}
return ;
}
Divide the Sequence的更多相关文章
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 2016 Multi-University Training Contest 5 Divide the Sequence
Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...
- 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 (贪心)
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 (训练题002 B)
Description Alice has a sequence A, She wants to split A into as much as possible continuous subsequ ...
- [HDOJ5783]Divide the Sequence(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783 题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0. 从后往前截取,这样不会影 ...
- HDU-5783 Divide the Sequence(贪心)
题目大意:给一个整数序列,将其划分成若干个子连续序列,使其每个子序列的前缀和不为负.求最大的划分个数. 题目分析:从后往做累加计算,如果不为负,则计数加一,累加和清0.否则,一直往前扫描.如果最终的和 ...
- 【贪心】HDU 5783 Divide the Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...
随机推荐
- js上传文件研究
https://github.com/shengulong/javascript-file-upload
- 使用RTL-SDR,从打开一个车门到批量打开车门
在最近几年,入侵汽车在当代社会的黑客圈中成为热点,很多文章表明汽车产业还有很多东西等待完善,在本篇文章中,我会让你熟悉我一直研究的一些概念,以及如何在网状网络中使用一些便宜的部件渗透远程开门系统. 软 ...
- Coursera 机器学习Course Wiki Lecture Notes
https://share.coursera.org/wiki/index.php/ML:Main 包含了每周的Lecture Notes,以便复习回顾的时候使用.
- 天下文章一大抄 mysql远程连接
使用GRANT命令创建远程连接mysql授权用户特定用户mysql -u root -ppassword 注意:p后面没有空格直接密码.mysql>grant all privileges ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part2
Use Cypress to test user registration Let’s write a test to fill out our registration form. Because ...
- 基于 orange(nginx+openresty) + docker 实现微服务 网关功能
摘要 基于 orange(nginx+openresty) + docker 实现微服务 网关功能 ;以实现 docker 独立容器 来跑 独立语言独立环境 在 同一个授权下 运行相关组合程序..年初 ...
- 使用BatteryHistorian分析和优化应用电量
欢迎Follow我的GitHub, 关注我的CSDN. 在Android项目中, 较难监控应用的电量消耗, 可是用户却很关心手机的待机时间. 过度耗电的应用, 会遭到用户无情的卸载, 不要存在侥幸心理 ...
- Java 实现原型(Prototype)模式
public class BaseSpoon implements Cloneable {//spoon 匙, 调羹 String name; public String getName() { re ...
- js中cookie的使用具体分析
JavaScript中的还有一个机制:cookie,则能够达到真正全局变量的要求. cookie是浏览器 提供的一种机制,它将document 对象的cookie属性提供 ...
- 【转载】.NET 框架浅析
经过了对C#较长时间的学习以及实践,不断地感受着.NET 框架--这个最本质,然而却似乎让人捉摸不透的概念.特别是经过拜读Anytao博主的<你必须知道的.NET>文章,使我对其概念关系得 ...