HDU-5783 Divide the Sequence(贪心)
题目大意:给一个整数序列,将其划分成若干个子连续序列,使其每个子序列的前缀和不为负。求最大的划分个数。
题目分析:从后往做累加计算,如果不为负,则计数加一,累加和清0。否则,一直往前扫描。如果最终的和为负,答案为0,否则为计数结果。
代码如下:
# include<iostream>
# include<cstdio>
# include<algorithm>
using namespace std;
# define LL long long const int N=1000000; int a[N+5]; int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;++i)
scanf("%d",a+i);
int ans=0;
LL sum=0;
for(int i=n-1;i>=0;--i){
sum+=(LL)a[i];
if(sum>=0){
++ans;
sum=0;
}
}
if(sum<0) cout<<0<<endl;
else cout<<ans<<endl;
}
return 0;
}
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(数列划分)
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 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 ...
- Divide the Sequence (贪心)
题意:求将一串数据尽可能多分成所有前缀和大于0的连续子串. 思路:由于是要求所有前缀和大于0,那么只要从后往前推就好了. #include<bits/stdc++.h> using nam ...
- 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 ...
- HDU5014Number Sequence(贪心)
HDU5014Number Sequence(贪心) 题目链接 题目大意: 给出n,然后给出一个数字串,长度为n + 1, 范围在[0, n - 1].然后要求你找出另外一个序列B,满足上述的要求,而 ...
随机推荐
- MainActivity获取fragment控件button监听报空指针错误
原因是是新版SDK创建项目时默认引入的fragment.xml,我的button是定义在fragment.xml里面的,而findviewbyid却是在main.activity里面调用的,而这样是获 ...
- IBM RSA 的语言设置
右键 IBM Rational software Architect for websphere software 快捷方式 ----> 打开文件位置 在 eclipse.ini 文件中添加参数 ...
- C++ primer的第三章的主要内容
第三章主要介绍了C++中标准库类型.主要讲到string和vector类型.在string类型中,能够很方便的操作字符串,应该要注意的地方就是它的字符串中元素的位置的类型是:size_type类型的数 ...
- 打造高质量Android应用:Android开发必知的50个诀窍
打造高质量Android应用:Android开发必知的50个诀窍
- 毕向东day01笔记--dos-jdk-jre-环境变量等
1.常用的dos命令,md,rd,dir,c:(进入C盘),del,set classpath 2.JDK和JRE之间的区别: JDK包含JER,JRE包含JVM. 3.环境变量的配置,静态配置--b ...
- SAP财务常用数据源概览
一. 0FI_GL_10总分类账:领先分类账余额 Delta Update : AIED After Images Marked for Deletion via Extractor (FI-GL/A ...
- hdoj-2025
#include "stdio.h"#include "string.h"void sort(char ch[],int count[],int n,int f ...
- C++ offsetof
这是一个宏,用于计算类中某个成员的地址相对于类实例的偏移量 在C++11中,要求这个类standard_layout 基本用法是这样子的: #include <stdio.h> /* pr ...
- Sql Server REPLACE函数的使用;SQL中 patindex函数的用法
Sql Server REPLACE函数的使用 REPLACE用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法REPLACE ( ''string_replace1'' ...
- android手机连接PC无法正常安装驱动
工作当中我们经常会遇到Android手机连接PC的时候无法正确安装驱动,或者安装失败.当然找到正确的驱动文件时首选的解决方案,如果正确的驱动文件依旧无法安装成功我们可以打开我的电脑-->属性-- ...