uva 1619 - Feel Good 一个技巧

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("\n");
        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\n",ans);
        printf("%lld %lld\n",ansl,ansr);
    }
    return 0;
}
时间: 2024-11-15 02:48:57

uva 1619 - Feel Good 一个技巧的相关文章

通用权限管理系统菜单展示的一个技巧

从这篇文章,希望您了解吉日嘎拉通用权限管理系统菜单项展示技巧. 项目中使用了吉日嘎拉的通用权限管理系统,几十个子系统均由该权限管理系统管理. 在系统中配置好相关菜单及非菜单项,配置截图: 菜单权限设置截图 通过下拉菜单进入其中的一个子系统 子系统中的菜单项(菜单项表示该项会在前端需要展示出来,用于用户点击的项目),其中的公开表示所有人均可看到该菜单项目. 子系统中的非菜单项(非菜单项表示该项目不需要在前端展示出来,比如有些在页面中的弹出窗口.按钮等项目) 通过单点登录到子系统以后,通过一个服务获

UVA 1619/POJ2796 滑窗算法/维护一个单调栈

Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12409   Accepted: 3484 Case Time Limit: 1000MS   Special Judge Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated

四、关于如何使用软件库的一个技巧-避免重复配置属性表

一.前言 我们需要使用各种函数库,比如Opencv,Itk, vtk,当不同的函数库使用的时候,在VS配置属性是一个很麻烦的问题,并且设计到不同函数库的交叉使用,所以这里提供一个小技巧. 那就是我们把每一个函数库的配置为属性表的形式(这个其实我在itk的安装里面已经介绍过),需要使用什么函数库的时候,我们只需要添加对应的属性表即可. 二.以QT使用vtk工程为例子 我们建立了一个工程以后,选择工程配置为release x64版本 1.选择属性管理器 2.右键添加-新建属性表 3.然后定义属性表格

TFS Build做Web应用持续集成发布的一个技巧

由于面向接口编程的关系,许多实现往往是动态注入运行,在一个项目中直接引用实现dll编译是不合理的.通常我们会在Post Build Event中添加一些xcopy命令将运行时才需要的dll复制到输出目录.在发布时会带来一些问题,比如:使用Visual Studio自带的Publish功能发布一个Web应用时就不会运行Post Build Event.同样的在基于TFS Build时也存在类似问题. TFS Build时会根据对应Definition的名称创建两个子目录:Source.Binari

UVA 1619 Feel Good(DP)

Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life. A new idea Bill has recently developed assigns a non-negat

给个什么标题呢?仅仅是一个技巧而已

Win32的消息机制是不停的循环处理当前应用程序的消息,但 WM_KEYDOWNWM_KEYUP WM_LBUTTONDOWNWM_LBUTTONUP 这两对消息很特别,当一直按着按键或鼠标键时你会发现一直触发WM_KEYDOWN或WM_LBUTTONDOWN消息,每触发一次消息,响应消息的逻辑就被调用一次,大都数情况下都是不对的,假如你用数字5浏览下30帧图片,数字6浏览上30帧图片,数字5你按得久一点就会发现此时的图片可能到了300帧,这肯定不是你想要的... 于是就有了这个技巧 .....

UVA 1619 Feel Good 感觉不错 (扫描法)

Feel Good Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories a

动态规划中转移方程的一个技巧

动态规划是一个很神奇的东西,总结一下自己写动态规划是的一些盲区! 有时候在定义状态的时候,可以用一定的方法,可以达到对转移时的时间复杂度起到很大的优化作用,以下面的题目来说明这点. Writing Code Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, t

UVA - 1619 Feel Good 标记+枚举

题目大意:给出n个正整数的序列,要求你找出符合sum(a1 + a2 + a3 + - + an) * min(a1,a2,-,an)的最大值,如果有多个符合条件的,输出最短序列 解题思路:从输出中观察得到,输出的答案要有三个,最大值,左端点,右端点. 那就设两个数组,纪录已当前数位最小值所能覆盖的最大区间,然后枚举每个数,求出区间和再乘上当前数求得值再进行比较 设置左右区间时,可以递归比较,假设l[i]纪录的时ai所能覆盖的最左端点,如果aj <= ai (j > i),那么l[j] = l