| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一直WA,各位大侠帮忙看看啊~~#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
int n;
struct rectangle
{
int index;
int height;
};
rectangle obj[100000];
stack<rectangle> astack;
int main()
{
int i;
__int64 s,ans=0;
rectangle tem;
while(cin>>n)
{
if(n==0) return 0;
ans=0;
for(i=0;i<n;i++)
{
cin>>obj[i].height;
obj[i].index=i;
}
astack.push(obj[0]);
for(i=1;i<n;i++)
{
if(astack.size()==0 || obj[i].height>=astack.top().height)//栈空的情况
astack.push(obj[i]);
else
{
while(astack.size()!=0 && obj[i].height<astack.top().height)
{
tem=astack.top();
astack.pop();
s=(__int64)(tem.height*(i-tem.index));
if(s>ans)
ans=s;
}
astack.push(obj[i]);//别忘了自己
}
}
while(astack.size()!=0)//最后栈不空的情况
{
tem=astack.top();
astack.pop();
s=(__int64)(tem.height*(i-tem.index));
if(s>ans)
ans=s;
}
printf("%I64d\n",ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator