poj 2796 Feel Good

本文介绍了一种计算人类生活期间情绪价值的方法,通过将每个日子分配一个非负整数值来量化其情绪价值,并通过特定公式计算出一段时间内的总情绪价值。文章提供了一个C++实现示例,用于找出具有最大情绪价值的生活阶段。

Description

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-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 daywas. 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 reflects that good on average period can be greatly spoiled by one very bad day. 

Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.


题意是给出一串数,求给定的范围内最小值乘该范围内所有值的和的最大值

方法和poj 2559相同,仍然是假设某一点的数值是最小的,求左右两端可到达的最远的位置

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 100000
using namespace std;
int n,a[MAX_N+5],l[MAX_N+5],r[MAX_N+5];
int main()
{
    while(~scanf("%d",&n))
    {
        long long sum[MAX_N+5];
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        l[0]=0,r[n+1]=0;
        for(int i=1;i<=n;i++)
        {
            int k=i-1;
            while(k>0&&a[i]<=a[k]) k=l[k]-1;
            l[i]=++k;
        }
        for(int i=n;i>=1;i--)
        {
            int k=i+1;
            while(k<n+1&&a[i]<=a[k]) k=r[k]+1;
            r[i]=--k;
        }
        sum[0]=0,sum[1]=a[1];
        for(int i=2;i<=n;i++)
            sum[i]=sum[i-1]+a[i];
        long long maxn=-1;
        int maxi;
        for(int i=1;i<=n;i++)
        {
            long long q=sum[r[i]]-sum[l[i]-1];
            q=a[i]*q;
            if(q>maxn) { maxn=q; maxi=i;}
        }
        printf("%lld\n",maxn);
        printf("%d %d\n",l[maxi],r[maxi]);
    }
    return 0;
}



下载方式:https://pan.quark.cn/s/c9b9b647468b ### 初级JSP程序设计教程核心内容解析#### 一、JSP基础概述JSP(JavaServer Pages)是由Sun Microsystems公司创建的一种动态网页技术规范,主要应用于构建动态网站及Web应用。JSP技术使得开发者能够将动态据与静态HTML文档整合,从而实现网页内容的灵活性和可变性。##### JSP的显著特性:1. **动态与静态内容的分离**:JSP技术支持将动态据(例如据库查询结果、实时时间等)嵌入到静态HTML文档中。这种设计方法增强了网页的适应性和可维护性。2. **易用性**:开发者可以利用常规的HTML编辑工具来编写静态部分,并通过简化的标签技术将动态内容集成到页面中。3. **跨平台兼容性**:基于Java平台的JSP具有优良的跨操作系统运行能力,能够在多种不同的系统环境中稳定工作。4. **强大的后台支持**:JSP能够通过JavaBean组件访问后端据库及其他资源,以实现复杂的据处理逻辑。5. **执行效率高**:JSP页面在初次被请时会被转换为Servlet,随后的请可以直接执行编译后的Servlet代码,从而提升了服务响应的效率。#### 二、JSP指令的运用JSP指令用于设定整个JSP页面的行为规范。这些指令通常放置在页面的顶部,向JSP容器提供处理页面的相关指导信息。##### 主要的指令类型:1. **Page指令**: - **语法结构**:`<%@ page attribute="value" %>` - **功能**:定义整个JSP页面的运行特性,如设定页面编码格式、错误处理机制等。 - **实例**: ...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值