HDU 5783 Divide the Sequence (贪心)
Divide the Sequence
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5783
Description
Alice 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.
Input
The 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.
Output
For each test case, output an integer indicates the maximum number of sequence division.
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
Source
2016 Multi-University Training Contest 5
##题意:
将数串A分解成尽可能多的字串,使得每个字串的任一前缀和都不小于零.
##题解:
贪心.
从后往前遍历,每个和为零的地方都可以分割一次.
注意用longlong.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 1010000
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n;
LL num[maxn];
int main(int argc, char const *argv[])
{
//IN;
//int t; cin >> t;
while(scanf("%d", &n) != EOF)
{
for(int i=1; i<=n; i++)
scanf("%I64d", &num[i]);
LL cur = 0;
int ans = 0;
for(int i=n; i>=1; i--) {
cur += num[i];
if(cur >=0) {
ans++;
cur = 0;
}
}
printf("%d\n", ans);
}
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 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,满足上述的要求,而 ...
随机推荐
- css控制UL LI 的样式详解
用<ul>设置导航 <style> #menu ul {list-style:none;margin:0px;} #menu ul li {float:left;} </ ...
- Python之格式化输出讲解
1.格式化输出整数python print也支持参数格式化,与C言的printf似, strHello = "the length of (%s) is %d" %(Hello W ...
- Linux 下查看文件字符编码和转换编码
Linux 下查看文件字符编码和转换编码 如果你需要在Linux中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而Linu ...
- 【Todo】深入理解Javascript系列
真的很好,要看 http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html
- inline-block和text-indent在IE6,IE7下同时使用的兼容问题解决方法
在实际应用中,考虑到seo,很多button,icon都要用到inline-block和text-indent来处理,例如: <a href="#">Button< ...
- js 写成类的形式 js 静态变量 js方法 属性 json类
function ClassStudentList() { //[{"Cid":"0d","Students":[{"Sid&qu ...
- [.NET WebAPI系列03] WebAPI Controller 中标准CRUD方法
[因] WebAPI的Controller中,一般都是下面四种方法: 对应于数据操作是我们通常所说的CRUD. C对应post,R对应Get,U对应Put,D对应Delete. 直接模仿VS 2012 ...
- Linux find xargs rm .orig
/********************************************************************* * Linux find xargs rm .orig * ...
- LeetCode Triangle 三角形(最短路)
题意:给一个用序列堆成的三角形,第n层的元素个数为n,从顶往下,每个元素可以选择与自己最近的两个下层元素往下走,类似一棵二叉树,求最短路. [], [,4], [6,,7], [4,,8,3] 注意: ...
- Swift入门篇-Hello World
提示:如果您使用手机和平板电脑看到这篇文章,您请在WIFI的环境下阅读,里面有很多图片, 会浪费很多流量. 博主语文一直都不好(如有什么错别字,请您在下评论)望您谅解,没有上过什么学的 最近这2天主要 ...