HDU 5783 Divide the Sequence (训练题002 B)
Description
Input
Each test case begin with an integer n in a single line.
The next line contains n
integers A_{1},A_{2}\cdots A_{n}
.
1 \leq n \leq 1e6
-10000 \leq A[i] \leq 10000
You can assume that there is at least one solution.
Output
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
- /*就是给你一个序列,让你求最多能分成多少段连续子序列,并且每段子序列的前缀个都得是大于等于0的;
- 思路就是从后往前遍历,要想分的最多那么有整数直接,当成一个数列就行了,有负数往前递加直到和为零。这里特别注意,数据要用long long要不然会溢出的
- */
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <string.h>
- #define N 1000005
- #define M (1<<15)+5
- #define INF 0x3f3f3f
- using namespace std;
- long long n,a[N],sum;
- int main()
- {
- //freopen("in.txt","r",stdin);
- while(scanf("%lld",&n)!=EOF)
- {
- memset(a,,sizeof(a));
- for(int i=;i<n;i++)
- {
- scanf("%lld",&a[i]);
- }
- long long cur=;
- for(int i=n-;i>=;i--)//这个是首位枚举
- {
- if(a[i]>=)
- cur++;
- else
- {
- sum=;
- for(;i>=;i--)
- {
- sum+=a[i];
- if(sum>=)
- {
- cur++;
- break;
- }
- }
- }
- }
- printf("%lld\n",cur);
- }
- return ;
- }
HDU 5783 Divide the Sequence (训练题002 B)的更多相关文章
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 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 5791 Two(训练题002 F)
Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002
题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...
随机推荐
- angular $compiler
directive是如何被compiled HTML编译发生在三个阶段: 1.$compile遍历DOM节点匹配directives 如果compiler找到元素上的directive,directi ...
- 《JavaScript闯关记》视频版硬广
<JavaScript闯关记>视频版硬广 stone 在菜航工作时,兼任内部培训讲师,主要负责 JavaScript 基础培训,2016年整理的<JavaScript闯关记>课 ...
- 如何实现跨 Docker 主机存储?- 每天5分钟玩转 Docker 容器技术(73)
从业务数据的角度看,容器可以分为两类:无状态(stateless)容器和有状态(stateful)容器. 无状态是指容器在运行过程中不需要保存数据,每次访问的结果不依赖上一次访问,比如提供静态页面的 ...
- win7旗舰版最新激活密钥
Win7旗舰.企业.专业版的激活密钥(32位.64位均可用).FJGCP-4DFJD-GJY49-VJBQ7-HYRR2 AcerVQ3PY-VRX6D-CBG4J-8C6R2-TCVBD Alien ...
- poj1067威佐夫博奕
取石子游戏 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31490 Accepted: 10374 Descripti ...
- 虚拟机中ubuntu-16.04 Linux系统下配置mysql数据库,并在windows下使用navicat远程连接
Linux系统下mysql数据库安装配置步骤: 1.在服务器上安装mysql:sudo apt-get install mysql-server sudo apt-get install mysql- ...
- ZOJ2067 经典 DP
题目:一个由'.'和'#'组成矩形,统计里面'.'组成的矩形的个数.点击打开链接 自己写挂了,懒得搞了 #include <stdio.h> #include <string.h&g ...
- Java面向对象 Object类 内部类
Java面向对象 Object类 内部类 知识概要: 一:Object类 二:内部类 匿名内部类的写法 1.Object O ...
- MyBatis Generator配置示例
(一).MBG介绍 MyBatis Generator(MBG)是一个Mybatis的代码生成器,它可以用来生成可以访问(多个)表的基础对象.MBG解决了对数据库操作有最大影响的一些简单的CRUD(插 ...
- javascript集合的交,并,补,子集,长度,新增,删除,清空等操作
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...