UVA - 1619 Feel Good(扫描法)
题目:

思路:
预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了。
这个预处理的技巧巧妙的用了之前的处理结果。(大佬tql)
代码:
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define MAX 1e3
#define FRE() freopen("in.txt","r",stdin)
#define FRO() freopen("out.txt","w",stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int maxn = ;
int r[maxn],l[maxn];
ll sum[maxn],a[maxn];
int n; int main(){
FRE();
int kase = ;
while(scanf("%d",&n)!=EOF){
sum[] = ;
a[] = a[n+] = -;
for(int i=; i<=n; i++){
scanf("%lld",&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]+];
}
} int L=,R=;//当不知道具体的边界的时候,就将边界设为开头
ll ans = a[]*a[];
for(int i=; i<=n; i++){
ll tsum = sum[r[i]] - sum[l[i]-];
if(ans < tsum * a[i]){
L = l[i];
R = r[i];
ans = tsum*a[i];
}
}
if(kase++){
printf("\n");
}
printf("%lld\n",ans);
printf("%d %d\n",L,R);
}
return ;
}
UVA - 1619 Feel Good(扫描法)的更多相关文章
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- UVA 1619 Feel Good 感觉不错 (扫描法)
Feel Good Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Bill is deve ...
- 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 ...
- uva 1619 - Feel Good || poj 2796 单调栈
1619 - Feel Good Time limit: 3.000 seconds Bill is developing a new mathematical theory for human ...
- [UVa 1619]Feel Good
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; struct node { int num; ...
- UVA 1619/POJ2796 滑窗算法/维护一个单调栈
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 12409 Accepted: 3484 Case T ...
- 【习题 8-18 UVA - 1619】Feel Good
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用单调队列求出l[i]和r[i] 分别表示i的左边最近的大于a[i]的数的位置以及i右边最近的大于a[i]的数的位置. 则l[i]+ ...
- 紫书 习题8-18 UVa 11536 (扫描法)
这道题貌似可以用滑动窗口或者单调栈做, 但是我都没有用到. 这道题要求连续子序列中和乘上最小值最大, 那么我们就可以求出每一个元素, 以它为最小值的的最大区间的值, 然后取max就ok了.那么怎么求呢 ...
随机推荐
- 深度理解apache 重写模块rewrite_mod,重写不再犯错
1.RewriteRule ^(com\/.*)$ index.php?do=$1 问:上面的规则匹配表达式 "^(.*)$" 匹配的内容是什么 答:匹配内容是URI站点目录:/d ...
- 【LNOI 2014】 LCA
[题目链接] 点击打开链接 [算法] 考虑求lca(x,y)的深度 我们可以将从根到x路径上的点都打上标记,然后,询问y到根上路径的权值和 那么,求sigma(depth(lca(i,z)))(l & ...
- RDA DEBUG
DEBUG寄存器:word 0xa0000010 word 0xa0000010 1 //debug开 word 0xa0000010 0 //debug关 当然也可以按模块打开/关闭debug信息, ...
- 一个单例(Singleton),并说明单例的目的和好处
单例的目的:保证一个类只有单一的实例,也就是说你无法通过new来创建这个类的一个新实例. 单例的好处:当一个对象在程序内部只能有一个实例的时候,它可以保证我们不会重复创建,而是始终指向同一个对象. S ...
- Win10出现键盘未失灵,按下的键都是快捷键的问题
某一天,WIN10开机.然后键盘莫名其妙的都无法正常使用,没有卡Window键,键盘也没有失灵,按下的键都成为了快捷键:终于在 https://zhidao.baidu.com/question/ ...
- [转]C语言字符串操作总结大全(超详细)
1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...
- 贪心+优先队列 HDOJ 5360 Hiking
题目传送门 /* 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀 ...
- kafka的topic命名技巧
不多说,直接上干货! 比如,我们给kafka的topic命名为user_r2p10 表示user这个topic的副本因子(r)是2,分区数(p)是10. 这样后期在写消费者代码的时候,根据top ...
- [转]iOS WebKit browsers and auto-zooming form controls
问题描述:https://github.com/jquery/jquery-mobile/issues/2581 本文转自:http://www.456bereastreet.com/archive/ ...
- python自动化--接口请求及封装
基于http协议,最常用的是GET和POST两种方法. 接口文档需要包含哪些信息: 接口名称接口功能接口地址支持格式 json/xml请求方式请求示例请求参数(是否必填.数据类型.传递参数格式)返回参 ...