POJ 2082 Terrible Sets(单调栈)
来源:互联网 发布:淘宝自动上架软件 编辑:程序博客网 时间:2024/05/17 21:45
题目链接:
POJ 2082 Terrible Sets
题意:
【题目描述成这样也是醉了。。。】
实际上就是给出
数据范围:
分析;
和前面那道题其实一样的,只要用一个
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;typedef long long ll;const int MAX_N = 50010;int n;ll height[MAX_N], width[MAX_N], sum[MAX_N];int L[MAX_N], R[MAX_N], sta[MAX_N];//维护单调非递减栈int main(){ while (~scanf("%d", &n)) { if(n == -1) break; sum[0] = 0; for (int i = 1; i <= n; ++i) { scanf("%lld%lld", &width[i], &height[i]); sum[i] = sum[i - 1] + width[i]; } height[n + 1] = 0, sum[n + 1] = sum[n]; int top = 0, cur; sta[0] = 0; for (int i = 1; i <= n + 1; ++i) { while(1) { cur = sta[top]; if (height[cur] <= height[i]) break; R[cur] = i; top--; } L[i] = cur; sta[++top] = i; } ll ans = 0; for (int i = 1; i <= n; ++i) { ll len = sum[R[i] - 1] - sum[L[i]]; //printf("L[%d] = %d R[%d] - 1 = %d\n", i, L[i], i, R[i] - 1); ans = max(ans, len * height[i]); } printf("%lld\n", ans); } return 0;}
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
- HDU:1702 ACboy needs your help again!(简单栈、队列)
- HDU1163 Eddy's digital Roots
- LeetCode1-Two Sum
- python的学习笔记
- 漫话中国古代史 —— 总论
- POJ 2082 Terrible Sets(单调栈)
- google gtest 快速入门
- poj 3320 Jessica's Reading Problem
- unity3d 第十四天
- 逐步深入三层架构(三)-三层登陆源码分享
- git rm/reset/checkout使用说明
- F28027第一节课---创建一个空的工程
- PHP的51个Memcached方法(12-21)
- ViewPager+Fragment+TabLayout联合使用