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 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 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.
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 first line of the input file contains n<tex2html_verbatim_mark> - the number of days of Bill's life he is planning to investigate (1n
100000)<tex2html_verbatim_mark> . The rest of the file contains n<tex2html_verbatim_mark> integer numbers a1, a2,..., an<tex2html_verbatim_mark> ranging from 0 to 106<tex2html_verbatim_mark> - 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 first line of the output file print the greatest value of some period of Bill's life.
On the second line print two numbers l<tex2html_verbatim_mark> and r<tex2html_verbatim_mark> such that the period from l<tex2html_verbatim_mark> -th to r<tex2html_verbatim_mark> -th day of Bill's life (inclusive) has the greatest possible value. If there are multiple periods with the greatest possible value, then print the shortest one. If there are still several possibilities, print the one that occurs first..
Sample Input
6
3 1 6 4 5 2
Sample Output
60
3 5
对于某个最小值ai来说,所选的区间应该尽量大,直到再选就不能保证ai是最小值的时候停止。
在扫描过程中维护一个向前延伸的最大位置,扩展的时候注意传递性,如果前面一个元素比它小,那么前面一个元素能延伸到的位置,
当前元素也可以延伸到,然后类似链表往前找的同时延伸链即可。向后找的时候类似。区间和用一个前缀和来处理。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
typedef long long ll;
int a[maxn],l[maxn],r[maxn],n;
ll sum[maxn]; int main()
{
int T = ; sum[] = ; a[] = -;
while(~scanf("%d",&n)){
if(T++) putchar('\n');
a[n+] = -;
for(int i = ; i <= n; i++)
scanf("%d",a+i),sum[i] = sum[i-]+a[i],l[i]=r[i]=i; for(int i = ; i <= n; i++){
while(a[i]<=a[l[i]-]) l[i] = l[l[i]-];
} for(int i = n; i >= ; i--){
while(a[i]<=a[r[i]+]) r[i] = r[r[i]+];
}
ll Max = (ll)a[]*a[];
int L = ,R = ;
for(int i = ; i <= n; i++){
ll tmp = (sum[r[i]]-sum[l[i]-])*a[i];
if(tmp > Max || (tmp == Max && R - L > r[i] - l[i] )){
Max = tmp;
L = l[i]; R = r[i];
}
}
printf("%lld\n%d %d\n",Max,L,R);
}
return ;
}
UVA 1619 Feel Good 感觉不错 (扫描法)的更多相关文章
- 推荐一些常用感觉不错的jQuery插件
转:http://www.cnblogs.com/v10258/p/3263939.html JQuery插件繁多,下面是个人在工作和学习中用到感觉不错的,特此记录. UI: jquery UI(官方 ...
- 最近发现docker感觉不错
最近发现docker感觉不错,接下来开始学习docker方面的技术.lxc也可以学学. storm,kafka也要熟悉起来.
- 逛csdn看见的一个知识阶梯,感觉不错
逛csdn看见的一个知识阶梯,感觉不错: 计算机组成原理 → DOS命令 → 汇编语言 → C语言(不包括C++).代码书写规范 → 数据结构.编译原理.操作系统 → 计算机网络.数据库原理.正则表 ...
- UVA - 1619 Feel Good(扫描法)
题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- 亲测!阿里云公共DNS,感觉不错!
最近阿里推出了公共DNS,这对于普通的网友来说估计没什么用处,但对于我们建站人来说,确实是一个不错的消息.一听说阿里出公共DNS,博主就立马换电信的DNS换下了.经过这几天的测试,相当满意! 个人感觉 ...
- UVA 1619 Feel Good(DP)
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...
- POJ 2796[UVA 1619] Feel Good
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16786 Accepted: 4627 Case T ...
- 第一次用python,成功的感觉不错。
自己的作业: 1. count = 0 while count <= 9 : count += 1 if count == 7 : continue print (count) 2. count ...
随机推荐
- Windows下怎样安装Tomcat
Tomcat 是开源的WEB应用容器,所以受到各位程序员和公司的亲赖.在这里给大家介绍一下如何在Windows环境下安装Tomcat绿色版本,希望能够对大家有帮助. 1.首先去Tomcat官网下载To ...
- 懒人模式开启Android模块自动化Api之旅
推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 在将业务进行模块化时,避免不了模块页面路由和模块通信, 大多数我 ...
- iOS内购流程一(协议、税务和银行业务)
协议.税务和银行业务,这一选项是当你App使用了In-app purchaes时候,你跟苹果签订协议的,需要签订合同和填写你的银行收款等信息 一.填写法人信息 1.登录iTunes Store,点击协 ...
- 图解SynchronousQueue原理详解-非公平模式
SynchronousQueue原理详解-非公平模式 开篇 说明:本文分析采用的是jdk1.8 约定:下面内容中Ref-xxx代表的是引用地址,引用对应的节点 前面已经讲解了公平模式的内容,今天来讲解 ...
- Python之将Python字符串生成PDF
笔者在今天的工作中,遇到了一个需求,那就是如何将Python字符串生成PDF.比如,需要把Python字符串'这是测试文件'生成为PDF, 该PDF中含有文字'这是测试文件'. 经过一番检索, ...
- 前端三部曲之Html -- 1(html的基本结构和常见的meta标签的作用)
一个H5页面的基本结构是什么 我么在编辑器中输入html:5可以得到 <!DOCTYPE html> <!-- 声明文档类型 --> <html lang="e ...
- UML工具 PlantUML SequenceDiagram
- excel 公式2列合并
=A2&"="&C2 ="UPDATE comm_department SET parent_id='"&D2&"' ...
- [題解](水/數學)luogu_P1147連續自然數和
尺取法a掉 然而數學解法為 等差數列求和公式: sum(L,R)=(L+R)(R-L+1)/2=M 即(L+R)(R-L+1)=2M 可以把2M分解成两个数之积,假设分成了两个数K1,K2,且K1&l ...
- python进阶03 继承
python进阶03 继承 一.继承 课堂练习:假设你正在参与一个魔幻类角色游戏的开发,公司需要腻味这个游戏设计两个角色的类: a.剑士 属性:1.角色名:2.角色等级:3.生命值:4.攻击力 行为: ...