zoukankan      html  css  js  c++  java
  • Divide the Sequence

    Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2232    Accepted Submission(s): 628

    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,A2An.
    1n1e6
    10000A[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

    题意:

    给定一串数字分成若干份,使任意份的任意前缀和都不为负。

    从后向前遍历贪心。

    附AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 
     8 int a[1000010];
     9 
    10 int main(){
    11     int n;
    12     while(~scanf("%d",&n)){
    13         int sum=n-1;
    14         for(int i=0;i<n;i++){
    15             scanf("%d",&a[i]);
    16         }
    17         int t=0;
    18         while(sum>=0){
    19             long long ans=0;
    20             ans+=a[sum];
    21             while(ans<0){
    22                 sum--;
    23                 ans+=a[sum];
    24             }
    25             t++;
    26             sum--;
    27         }
    28         printf("%I64d
    ",t);
    29 }
    30     return 0;
    31 }
  • 相关阅读:
    serial number
    python getopt
    python readline,seek
    linux scp
    jenkinsapi
    windows kill process
    python time
    python configparse
    解决某些.net不方便解决的问题,解决方法就是 DHTML
    (转)windows XP 系统服务“关闭”详细列表,释放N多内存,128也够用了!
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5745543.html
Copyright © 2011-2022 走看看