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了.那么怎么求呢 ...
随机推荐
- hibernate 下载
https://sourceforge.net/projects/hibernate/files/hibernate-orm/5.0.7.Final/ http://sourceforge.net/p ...
- 学习MAP 地图好地址
http://www.cnblogs.com/beniao/archive/2010/01/13/1646446.html Bēniaǒ成长笔记在IT江湖里我不是一名老手,我只是一名普通的程序员,愿意 ...
- A Go library implementing an FST (finite state transducer)——mark下
https://github.com/couchbaselabs/vellum Building an FST To build an FST, create a new builder using ...
- .NET Runtime version 2.0.50727.8762 - 执行引擎错误(7969097A) (80131506)
VS2010调试IIS发布的web工程提示:无法连接到 Visual Studio 开发服务器 .NET Runtime version 2.0.50727.8762 - 执行引擎错误(7969097 ...
- 为什么JavaWeb项目要分层
首先让我们坐着时光机回到n年前的web开发.那个时候最早都是静态的html页面,后来有了数据库,有了所谓的动态页面,然后程序猿在编码的时候,会把所有的代码都写在页面上,包括数据库连接,包括事务控制,接 ...
- bzoj 1782: [Usaco2010 Feb]slowdown 慢慢游【dfs序+线段树】
考虑每头牛到达之后的影响,u到达之后,从1到其子树内的点需要放慢的都多了一个,p为u子树内点的牛ans会加1 用线段树维护dfs序,每次修改子树区间,答案直接单点查询p即可 #include<i ...
- 清北刷题10.23night
NOIP 模拟赛 张若天 年 ⽉ ⽇ 题⽬名称 监听 实验室 ⽂明 可执⾏⽂件名 monitor lab civilization 输⼊⽂件名 monitor.in lab.in civilizati ...
- Moco模拟服务器post&get请求 (二)
1.moco启动命令如下:java -jar moco-runner-0.12.0-standalone.jar 协议类型 -p 端口号 -c json配置文件 2.带参数的get请求 [ { &qu ...
- sql注入方法以及防范
sql注入方法: 1.数字注入 ; get请求 www.bobo.com?id=1 可以查出 ID等于1的一条数据. 如果有人在链接后面增加 www.bobo.com?id=1 or 1=1 / w ...
- http升级https(转)
让你的网站免费支持 HTTPS 及 Nginx 平滑升级 为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上 ...