您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: