zoukankan      html  css  js  c++  java
  • ZROI#592

    ZROI#592

    题目链接
    简化题意:
    给定一个序列,求出以每个元素为端点的使得和最大的子段的另一个端点.
    就按照最大子段和的常规(DP),记录一下转移,正反分别跑一遍就行了.
    输出的时候正着反着哪一边大就输出哪一边的端点.
    (Code:)

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define MEM(x,y) memset ( x , y , sizeof ( x ) )
    #define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
    #define per(i,a,b) for (int i = a ; i >= b ; -- i)
    #define pii pair < int , int >
    #define X first
    #define Y second
    #define rint read<int>
    #define int long long
    #define pb push_back
    
    using std::set ;
    using std::pair ;
    using std::max ;
    using std::min ;
    using std::priority_queue ;
    using std::vector ;
    using std::swap ;
    using std::sort ;
    using std::unique ;
    using std::greater ;
    
    template < class T >
        inline T read () {
            T x = 0 , f = 1 ; char ch = getchar () ;
            while ( ch < '0' || ch > '9' ) {
                if ( ch == '-' ) f = - 1 ;
                ch = getchar () ;
            }
            while ( ch >= '0' && ch <= '9' ) {
                x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
                ch = getchar () ;
           }
       return f * x ;
    }
    
    const int N = 1e5 + 100 ;
    
    int f[N] , n , v[N] , g[N] ;
    int pre[N] , suf[N] ;
    
    signed main (int argc , char * argv[] ) {
        n = rint () ; rep ( i , 1 , n ) v[i] = rint () ;
        f[1] = v[1] ; g[n] = v[n] ;
        rep ( i , 1 , n ) suf[i] = pre[i] = i ;
        rep ( i , 2 , n ) {
            f[i] = max ( v[i] , f[i-1] + v[i] ) ;
            if ( v[i] > f[i-1] + v[i] ) pre[i] = pre[i] ;
            else pre[i] = pre[i-1] ;
        }
        per ( i , n - 1 , 1 ) {
            g[i] = max ( v[i] , g[i+1] + v[i] ) ;
            if ( v[i] >= g[i+1] + v[i] ) suf[i] = suf[i] ;
            else suf[i] = suf[i+1] ;
        }
        rep ( i , 1 , n ) printf ("%lld " , f[i] >= g[i] ? pre[i] : suf[i] ) ;
        return 0 ;
    }
    
    May you return with a young heart after years of fighting.
  • 相关阅读:
    将才和帅才之的区别
    百胜集团XX:BPM实现业务流程全过程无缝链接(案例)
    心、肝、脾、肺、肾五脏解说+ 五脏六腑的作用
    人体的五行属性
    易经卦的通例
    《孙子兵法》中的企业领导艺术和方法
    五行盘谱
    大容量高并发性服务器组的技术解析
    中华哲学的领导艺术
    如何在WINDOW环境下搭建ActivateMQ和zookeeper集群环境
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11459475.html
Copyright © 2011-2022 走看看