HDU5783(2016多校第五场)——Divide the Sequence(水水水)
2016-08-07 16:48
447 查看
New~ 欢迎参加2016多校联合训练的同学们~ |
Divide the SequenceTime Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 962 Accepted Submission(s): 471 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。
看代码把。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std;
const int INF=1000000007;
const int MAXN =1000010;
const int MAXM=1000010;
long long a[MAXN];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++)
scanf("%I64d",a+i);
int cnt=0;
long long s=0;
for(int i=n;i>=1;i--){
if(a[i]>=0&&s==0)
cnt++;
else if(a[i]<0){
s+=a[i];
}
else if(a[i]>=0&&s!=0){
s+=a[i];
if(s>=0)
{
cnt++;
s=0;
}
}
}
printf("%d\n",cnt);
}
}
相关文章推荐
- HDOJ 5783 (2016多校联合训练 Training Contest 5) Divide the Sequence
- 2016多校5 hdoj5783 Divide the Sequence
- 2016 多校 Multi-University Training Contest 5 Divide the Sequence
- (多校第五场1003)HDU5773 Divide the Sequence
- HDU5783 - Divide the Sequence(2016 Multi-University Training Contest 5 - C)
- hdu 5783 Divide the Sequence(2016 Multi-University Training Contest 5——水题)
- HDU5783 Divide the Sequence(贪心)
- (HDU 5783)Divide the Sequence <思维水题> 多校训练5
- 【HDU5783】Divide the Sequence(贪心)
- 2016 Multi-University Training Contest 5 1003 Divide the Sequence (贪心)
- hdu5783(2016多校第五场,dp)
- 2016 Multi-University Training Contest 5 1003 Divide the Sequence
- HDU 5783 Divide the Sequence 2016 Multi-University Training Contest 5
- Divide the Sequence
- HDOJ 5773 (2016多校联合训练 Training Contest 4) The All-purpose Zero
- 2016多校5 hdu 5783 Divide the Sequence 贪心
- hdu 5783 Divide the Sequence 贪心
- hdu 5782 Cycle (2016多校第五场1002) 后缀数组
- 【HDOJ5783】Divide the Sequence(贪心)
- 2018年全国多校算法寒假训练营练习比赛(第五场)The Biggest Water Problem