zoukankan      html  css  js  c++  java
  • uva 1619

    1619 - Feel Good

    Time limit: 3.000 seconds

     
    Bill is developing a new mathematical theory for human emotions. His recent investigations are dedi-
    cated to studying how good or bad days in uent people's memories about some period of life.
    A new idea Bill has recently developed assigns a non-negative integer value to each day of human
    life. Bill calls this value the
    emotional value
    of the day. The greater the emotional value is, the better
    the day was. Bill suggests that the value of some period of human life is proportional to the sum of the
    emotional values of the days in the given period, multiplied by the smallest emotional value of the day
    in it. This schema re ects that good on average period can be greatly spoiled by one very bad day.
    Now Bill is planning to investigate his own life and nd the period of his life that had the greatest
    value. Help him to do so.
    Input
    The input will contain several test cases, each of them as described below. Consecutive test cases are
    separated by a single blank line.
    The rst line of the input le contains
    n
    | the number of days of Bill's life he is planning to
    investigate (1
    n
    100000). The rest of the le contains
    n
    integer numbers
    a
    1
    ;a
    2
    ;:::;a
    n
    ranging
    from 0 to 10
    6
    | the emotional values of the days. Numbers are separated by spaces and/or line breaks.
    Output
    For each test case, the output must follow the description below. The outputs of two consecutive cases
    will be separated by a blank line.
    On the rst line of the output le print the greatest value of some period of Bill's life.
    On the second line print two numbers
    l
    and
    r
    such that the period from
    l
    -th to
    r
    -th day of Bill's
    life (inclusive) has the greatest possible value. If there are multiple periods with the greatest possible
    value, then print any one of them.
    SampleInput
    6
    3 1 6 4 5 2
    SampleOutput
    60
    3 5
    题意:得到max(一个区间的sum*min);
    思路:遍历这个序列,得到以该点为最小值的区间;
       单调栈实现;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 100000007
    #define esp 0.00000000001
    const int N=1e5+10,M=1e6+10,inf=1e9;
    ll d[N];
    ll a[N];
    ll l[N];
    ll r[N];
    ll sum[N];
    void init(ll x)
    {
        ll k=0;
        a[0]=-1;
        a[x+1]=-1;
        for(ll i=1;i<=x;i++)
        sum[i]=sum[i-1]+a[i];
        k=0;
        d[++k]=0;
        for(ll i=1;i<=x;i++)
        {
            while(a[d[k]]>=a[i])k--;
            l[i]=d[k];
            d[++k]=i;
        }
        k=0;
        d[++k]=x+1;
        for(ll i=x;i>=1;i--)
        {
            while(a[d[k]]>=a[i])k--;
            r[i]=d[k];
            d[++k]=i;
        }
    }
    int main()
    {
        ll x,y,z,i,t;
        int flag=0;
        while(~scanf("%lld",&x))
        {
            if(flag)
            printf("
    ");
            flag++;
            for(i=1;i<=x;i++)
            scanf("%lld",&a[i]);
            init(x);
            ll ans=0;
            ll ansl=1,ansr=1;
            for(i=1;i<=x;i++)
            {
                ll k=(sum[r[i]-1]-sum[l[i]])*a[i];
                if(k>ans)
                {
                    ans=k;
                    ansl=l[i]+1;
                    ansr=r[i]-1;
                }
            }
            printf("%lld
    ",ans);
            printf("%lld %lld
    ",ansl,ansr);
        }
        return 0;
    }
  • 相关阅读:
    Hadoop集群VSFTP和SecureCRT安装配置
    Hadoop集群完全分布式坏境搭建
    Hadoop集群坏境搭建配置
    Hadoop集群坏境CentOS安装
    Pr视频剪辑基础技巧学习
    SAN和NAS之间的基本区别
    原始容量、可用容量和有效容量的区别
    解释一下什么是网盘与云盘
    纠错技术之FEC(向前纠错)
    分布式存储的冗余类型(N+2:1)
  • 原文地址:https://www.cnblogs.com/jhz033/p/5658493.html
Copyright © 2011-2022 走看看