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 ...
随机推荐
- matlab新手入门(四)(翻译)
工作空间变量 工作区包含您在数据文件或其他程序中创建或导入到MATLAB®中的变量. 例如,这些语句在工作空间中创建变量A和B. A=255; b=ones(size(Img)); 您可以使用whos ...
- HRBUST - 1819 石子合并问题--圆形版(区间dp+环形+四边形优化)
石子合并问题--圆形版 在圆形操场上摆放着一行共n堆的石子.现要将石子有序地合并成一堆.规定每次只能选相邻的两堆合并成新的一堆,并将新的一堆石子数记为该次合并的得分.请编辑计算出将n堆石子合并成一堆的 ...
- 使用的SQLServer版本不支持数据类型“datetime2“
快速解决方法: 原因,在使用ado.net entity的时候,entity使用的数据库是sqlserver 2008, 但后来实际使用中使用的数据库是sqlserver 2005, 操作DateTi ...
- Unity ShaderLab 光照随笔
unity camera默认3种渲染路径,unity5.50里面有4种 camera Rendering Path 1 vertexLit(逐顶点,一般在vert中处理) 2 forward (前向 ...
- windows 10 删除库后自动恢复的解决方法
目录 什么是windows 库? 手动删除不行吗? 如何正确的"删除"? title: windows 10 删除库后自动恢复的解决方法 date: 2019-06-09 15:4 ...
- PHP闭包和匿名函数
概念 闭包和匿名函数在PHP5.3.0中被引入. 闭包 闭包是指创建时封装周围环境的函数.即使闭包所在的环境不存在了,闭包中封装的状态依然存在.这个概念很难理解,不过没关系,继续看下去就会明白了. 匿 ...
- django-跨域访问
pip install django-cors-headers #安装cors INSTALLED_APPS = [ ... 'corsheaders', ... ] MIDDLEWARE_CLASS ...
- TDH-search汇报理解
题目:海量数据查询开头:1.自我介绍:2.题目切入: 什么是海量数据查询?(海量数据,快速,符合要求) 几个常用场景(搜索引擎,百度:话单查询:影像平台,高铁)3.展示目录:架构,案例,平台规划 4. ...
- CellSet 遍历
CellSet 结构: 查询MDX: SELECT NON EMPTY {{ {{ {{ {{ {{ AddCalculatedMembers([店铺.店铺ID].[店铺ID].Members)}} ...
- Spark Mllib里如何提取每个字段并转换为***类型(图文详解)
不多说,直接上干货! 具体,见 Hadoop+Spark大数据巨量分析与机器学习整合开发实战的第17章 决策树多元分类UCI Covertype数据集