| ||||||||||
| 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了n遍终于a了。
看开网上的题解和源码也不靠谱啊。还得字节写。
在数列的最后加上一个0,保证最后出栈能够top==0;
如果当前高度>栈顶高度,压栈。
否则出栈:
else
{
flag=0;
while(top>=0 && z[top].h>a[i])
{
flag=1;
tot=(i-1-z[top].id+1)*z[top].h;
if(tot>ans)
ans=tot;
top--;
}
top++;
z[top].h=a[i];
if(flag==0)
z[top].id=i;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator