题意:求将一串数据尽可能多分成所有前缀和大于0的连续子串。

  思路:由于是要求所有前缀和大于0,那么只要从后往前推就好了。

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e6 + ;
long long arr[maxn], n; int main(){
while(~scanf("%d", &n)){
for(int i = ; i < n; i ++) scanf("%lld", &arr[i]);
int ans = ;
long long sum = ;
for(int i = n - ; i >= ; i --) {
sum += arr[i];
if(sum >= ){
ans ++;
sum = ;
}
}
printf("%d\n",ans);
}
return ;
}

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(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. HDU 5783 Divide the Sequence

    Divide the Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. 2016 Multi-University Training Contest 5 Divide the Sequence

    Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...

  6. HDU5014Number Sequence(贪心)

    HDU5014Number Sequence(贪心) 题目链接 题目大意: 给出n,然后给出一个数字串,长度为n + 1, 范围在[0, n - 1].然后要求你找出另外一个序列B,满足上述的要求,而 ...

  7. 【题解】Cut the Sequence(贪心区间覆盖)

    [题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ...

  8. 【贪心】HDU 5783 Divide the Sequence

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...

  9. [HDOJ5783]Divide the Sequence(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783 题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0. 从后往前截取,这样不会影 ...

随机推荐

  1. Thinkphp5.1 模板路径报错

    版本:5.1.24   ,windows环境 报错: 模板文件不存在:template\index\default\index\index.html 1.报错原因:linux/windows   对大 ...

  2. 【ERROR】no matching function for call to 'std::basic_ifstream<char>::basic_ifstream

    错误记录:QT中使用 no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(QString ...

  3. 安装Conda并在Conda下安装jupyter notebook

    1:安装 conda install jupyter notebook 2:启动 jupyter notebook

  4. 【html5】 解决 video标签 不自动全屏

    <video controls="controls" poster='' src='' preload="auto" x5-playsinline=&qu ...

  5. Redis 主从配置(Windows版)

    安装从库 1.复制一份 Redis 文件,当做从库. 2.修改从库文件中 redis.windows.conf 的端口号. 3.安装服务,需要重新设置名称.然后去服务中,开启“redis6380”(此 ...

  6. GO语言-基础语法:变量定义

    package main import ( "fmt" ) //不在函数内的变量,属于包内的变量.不能使用":="进行定义和赋值 var ( bb = cc = ...

  7. 1.9flask sqlalchemy和wtforms

    2019-1-9 15:28:07 还有2天视频flask结束,然后到爬虫了 发现好快 学的东西好多! 到时候来个综合整理!!!! 越努力,越幸运!!! sqlalchemy 参考连接: https: ...

  8. mybatis02--增删改查

    1.修改StudentDao public interface StudentDao { /** * 新增学生信息 */ void addStudent(Student student); // 新增 ...

  9. hibernate09--连接查询

    创建实体类 package cn.bdqn.bean; import java.util.ArrayList; import java.util.Date; import java.util.List ...

  10. java基础学习总结——流

    一.JAVA流式输入/输出原理