poj 2082 Terrible Sets(单调栈)
来源:互联网 发布:大数据利弊 编辑:程序博客网 时间:2024/05/21 08:48
#include<cstdio>#define MAX_N 50050#define MAX(x,y) ((x)>(y)?(x):(y))using namespace std;int stack[MAX_N],l[MAX_N],r[MAX_N],d[MAX_N],w[MAX_N];int n;int cal(){int tot=0;for(int i=0;i<n;i++){while(tot>0&&d[stack[tot-1]]>=d[i])tot--;l[i]=tot==0?0:(stack[tot-1]+1);stack[tot++]=i;}tot=0;for(int i=n-1;i>=0;i--){while(tot>0&&d[stack[tot-1]]>=d[i])tot--;r[i]=tot==0?n:stack[tot-1];stack[tot++]=i;}long long res=0;for(int i=0;i<n;i++)res=MAX(res,d[i]*(w[r[i]]-w[l[i]]));return res;}int main(){while(~scanf("%d",&n)&&(n!=-1)){int temp;w[0]=0;for(int i=0;i<n;i++){scanf("%d%d",&temp,&d[i]);w[i+1]=w[i]+temp; }printf("%d\n",cal());}}
0 0
- POJ 2082 Terrible Sets(单调栈)
- POJ-2082 Terrible Sets (单调栈)
- POJ 2082 Terrible Sets 单调栈
- 【POJ】2082 - Terrible Sets(单调栈)
- POJ 2082 Terrible Sets(单调栈)
- poj 2082 Terrible Sets(单调栈)
- POJ 2082 Terrible Sets 单调栈基础
- poj 2082 Terrible Sets(单调栈)
- poj 2082 Terrible Sets【单调栈】
- poj 2082 Terrible Sets (单调栈)
- POJ 2082 Terrible Sets 单调栈的应用
- POJ 题目2082 Terrible Sets(单调栈)
- Terrible Sets——poj-2082——单调栈
- POJ 2082 Terrible Sets(栈)
- poj2082 Terrible Sets 单调栈
- POJ2082---Terrible Sets(单调栈)
- Terrible Sets *---* 单调栈解决问题
- POJ 2082 Terrible Sets
- spring框架学习
- 训练网址
- android ipc通讯基础疑问点二
- MySQL中MyISAM与InnoDB区别及选择
- MyBatis--关联关系查询--多对一--多表单独查询
- poj 2082 Terrible Sets(单调栈)
- unity基础UI梳理--text
- Nginx+Tpmcat 负载均衡
- 视觉词袋模型BOW学习笔记及matlab编程实现
- “抽奖”的 Web 开发实现
- Ignatius and the Princess IV HDU
- 关于java推送自己写的一点心得做个记录
- MyBatis-2 全局配置文件
- Linux下安装redis