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

    Divide the Sequence

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


    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
     
    Author
    ZSTU

    贪心。尽量一个个选。考虑到前缀不能为负,可以倒着扫一遍

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/8/2 12:04:29
    File Name     :p512.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 1000010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int a[maxn];
    int vis[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
       // freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int n;
        while(cin>>n){
            int mark=0;
            cle(vis);
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
                if(a[i]<0)mark=1,vis[i]=1;
            }
            if(!mark){
                printf("%d
    ",n);continue;
            }
            ll ans=0;
            for(int i=n;i>=1;i--){
                if(vis[i]){
                    ll sum=a[i];
                    while(sum<0){
                        i--;
                        sum+=a[i];
                    }
                }
                ans++;
            }
            printf("%I64d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    MVC5+EF6简单实例以原有SQLServer数据库两表联合查询为例
    ArcGIS生成根据点图层生成等值面并减小栅格锯齿的操作步骤
    EF6+MVC5之Oracleo数据库的Code First方式实现
    jquery写的tab切换效果 非常简单
    APP消息推送是否进入消息中心和click、receive事件分析
    Android APP切换到后台接收不到推送消息
    js写的简单轮播图
    凉凉的笔记 two day
    凉凉的笔记 one.day
    在SQL Server数据库中批量导入数据的四种方法
  • 原文地址:https://www.cnblogs.com/pk28/p/5730319.html
Copyright © 2011-2022 走看看