hdu 5783 Divide the Sequence(2016 Multi-University Training Contest 5——水题)
2016-08-04 11:43
459 查看
题目大意:http://acm.hdu.edu.cn/showproblem.php?pid=5783
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 754 Accepted Submission(s): 396
Problem 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
Author
ZSTU
Source
2016 Multi-University Training Contest 5
题目大意:给一个序列,要尽可能多的分成很多子序列。使得每个子序列的前缀和都大于等于0,最后输出符合条件的子序列个数。
解题思路:
倒序遍历一遍序列,如果这个数大于等于0,就是符合条件的序列,否则就往前加,直到加到大于等于0即可符合条件。
详见代码。
Divide the Sequence
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 754 Accepted Submission(s): 396
Problem 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
Author
ZSTU
Source
2016 Multi-University Training Contest 5
题目大意:给一个序列,要尽可能多的分成很多子序列。使得每个子序列的前缀和都大于等于0,最后输出符合条件的子序列个数。
解题思路:
倒序遍历一遍序列,如果这个数大于等于0,就是符合条件的序列,否则就往前加,直到加到大于等于0即可符合条件。
详见代码。
#include <iostream> #include <cstdio> using namespace std; #define ll long long ll a[1000010]; int main() { int n; ll sum,s; while (~scanf("%d",&n)) { sum=s=0; for (int i=1; i<=n; i++) { scanf("%lld",&a[i]); } for (int i=n; i>=1; i--) { sum+=a[i]; //cout<<sum<<endl; if (sum>=0) { s++; sum=0; } } printf ("%lld\n",s); } return 0; }
相关文章推荐
- HDU 5783 Divide the Sequence 2016 Multi-University Training Contest 5
- HDU5783 - Divide the Sequence(2016 Multi-University Training Contest 5 - C)
- 2016 多校 Multi-University Training Contest 5 Divide the Sequence
- 2016 Multi-University Training Contest 5 1003 Divide the Sequence (贪心)
- 2016 Multi-University Training Contest 5 1003 Divide the Sequence
- hdu 5867 Water problem(2016 Multi-University Training Contest 10——水题)
- hdu 5828 2016 Multi-University Training Contest 8 Rikka with Sequence 解题报告
- HDOJ 5783 (2016多校联合训练 Training Contest 5) Divide the Sequence
- (HDU 5744)Keep On Movin <回文数,思维水题> 2016 Multi-University Training Contest 2
- hdu 5752 Sqrt Bo(2016 Multi-University Training Contest 3——水题)
- hdu 5742 It's All In The Mind(2016 Multi-University Training Contest 2——思维题)
- (HDU 5742) It's All In The Mind <思维水题> 2016 Multi-University Training Contest 2
- 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树区间更新+差分数组)
- hdu 5821 2016 Multi-University Training Contest 8 Ball 解题报告
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5744 Keep On Movin// 2016 Multi-University Training Contest 2
- 2016 Multi-University Training Contest 4 hdu 5774 Where Amazing Happens【map+(ctrl+c)+(ctrl+v)】
- HDU 5769-->Substring-->2016 Multi-University Training Contest 4
- (HDU 5831)2016 Multi-University Training Contest 8 Rikka with Parenthesis II(水?)
- hdu 5821 2016 Multi-University Training Contest 8(排序)