POJ-2796-Feel Good-萌萌的单调栈
2015-08-26 09:12
316 查看
给一数组
设数组参考值为该区间和乘上区间内最小值
求数组内最大的参考值
用的也是单调栈的思想做的
这里区间和 先用前缀和预处理好了;
ps:看讨论区有人用什么rmq、dp+树状数组做的。待会也试试
设数组参考值为该区间和乘上区间内最小值
求数组内最大的参考值
用的也是单调栈的思想做的
这里区间和 先用前缀和预处理好了;
ps:看讨论区有人用什么rmq、dp+树状数组做的。待会也试试
<pre name="code" class="cpp">#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <iostream> #include <queue> #include <map> #include <set> #include <vector> using namespace std; __int64 max (__int64 a,__int64 b) {return a<b?b:a;} struct node { int w; int s; int e; }; node tm[100005]; __int64 top; __int64 anse,anss; __int64 ans; __int64 sum[100005]; int main() { __int64 n,i; scanf("%I64d",&n); ans=top=0; node tt; for (i=1;i<=n;i++) { scanf("%d",&tt.w); sum[i]=sum[i-1]+tt.w; tt.e=tt.s=i; while(top&& tm[top].w>=tt.w) { tm[top-1].e=tm[top].e; __int64 tol=(sum[tm[top].e]-sum[tm[top].s-1]) * tm[top].w; //计算top处的区间参考值 if (tol>=ans) { ans=tol; anss=tm[top].s; anse=tm[top].e; } tt.s=tm[top].s; top--; } tm[++top]=tt; } while(top) { tm[top-1].e=tm[top].e; __int64 tol=(sum[tm[top].e]-sum[tm[top].s-1]) *tm[top].w; if (tol>=ans) { ans=tol; anss=tm[top].s; anse=tm[top].e; } top--; } printf("%I64d\n%I64d %I64d\n",ans,anss,anse); return 0; }
相关文章推荐
- 基于服务器时间的倒计时功能js
- js基于服务器时间的倒计时功能
- 前端构建工具gulpjs的使用介绍及技巧
- js基于服务器时间的倒计时功能
- jQuery 遍历 json 方法大全
- HTML 5 Web 存储提供了几种存储数据的方法
- javascript中alert()与console.log()的区别
- 静态分析中”Potential null dereference”的处理
- 验证整数、小数、实数、有效位小数最简单JavaScript正则表达式
- Buffer创始人谈开发:先验证,后开发!
- JQuery Mobile 简单入门引导
- jQuery的deferred对象详解
- jQuery如何实现点击页面获得当前点击元素
- HTML5 Introduction
- 集群环境下JSP中获取客户端IP地址的方法
- [ACdream 1211 Reactor Cooling]无源无汇有上下界的可行流
- JQUERY 模糊选择
- Json 入门例子【3】
- webapi 返回Json数据格式中的null值替换
- node-zk-browser安装配置