HDOJ 最大矩形面积 栈
2016-08-10 19:54
134 查看
精度很重要,看到大数字就要注意是否要使用long long 或者是 __int64
#include"iostream" #include"cstdio" #include"algorithm" #include"vector" #include"string" #include"stack" using namespace std; const int maxn=100000+10; __int64 height[maxn]; stack<int>Stack; int n; __int64 solution() { __int64 Max=0; for(int i=0;i<=n;i++) { __int64 high=(i==n?0:height[i]); if(Stack.empty()||high>=height[Stack.top()]) Stack.push(i); else { int tp=Stack.top(); Stack.pop(); Max=max(Max,__int64(height[tp]*(Stack.empty()?i:i-Stack.top()-1))); i--; } } return Max; } int main() { //freopen("a.txt","r",stdin); while(scanf("%d",&n),n) { while(!Stack.empty()) Stack.pop(); for(int i=0;i<n;i++) scanf("%I64d",height+i); printf("%I64d\n",solution()); } return 0; }
相关文章推荐
- HDOJ 1506 矩形最大面积
- 最大连续矩形面积
- 栈——largest-rectangle-in-histogram求柱形图中的最大矩形面积
- Largest Rectangle in a Histogram(动态规划找最大矩形面积)
- lintcode[122]:直方图内最大矩形面积
- LeetCode | Largest Rectangle in Histogram(直方图围城的最大矩形面积)
- HDU1505(最大矩形面积+DP)
- 美团2017编程题—拼凑钱币&大富翁游戏&最大矩形面积&最长公共连续子串
- POJ 2082 Terrible Sets 51nod 1102 面积最大的矩形 《题意好难懂---<贪心+单调栈>》
- 51nod 1102 面积最大的矩形
- 柱状图内最大的矩形面积 Largest Rectangle in Histogram @LeetCode
- 寻找直方图中面积最大的矩形 --- 庞果网
- hdoj 2056 Rectangles 【求矩形面积】
- HDU 1505 City Game (最大子矩形面积)
- HDU 2870 Largest Submatrix (最大子矩形面积)
- 51nod 1102 面积最大的矩形(单调栈)
- poj3494 连续区域最大矩形面积 我要做的足够 强大
- 求柱形图中的最大矩形面积
- 寻找直方图中面积最大的矩形(C语言版)
- CodeForces 22B Bargaining Table 01矩阵求最大矩形面积