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 |
做恶心了 帮帮看看哪里错了#include <iostream> #include <stack> using namespace std; __int64 sum[100010],a[100010],b[100010],top,e,d[100010]; int main() { stack<__int64> intstack; stack<__int64> intstack2; __int64 max; int i,j,len,l,n; while(cin>>n) { if(n==0) break; scanf("%I64d",&a[0]); intstack.push(a[0]); b[0]=0; intstack2.push(b[0]); for(i=1;i<n;i++) { scanf("%I64d",&a[i]); len=intstack.size()-1; l=0; for(j=len;j>=0;j--) { if(intstack.empty()) { intstack.push(a[i]); b[i]=0; intstack2.push(b[i]); } else if(a[i]<=intstack.top()) { l=1; b[i]=intstack2.top(); top=intstack2.top(); intstack.pop(); intstack2.pop(); if(intstack.empty()) { intstack.push(a[i]); intstack2.push(b[i]); } } else { if(l==0) { b[i]=i; intstack.push(a[i]); intstack2.push(b[i]); } else { b[i]=top; intstack.push(a[i]); intstack2.push(top); } } } } for(i=intstack.size()-1;i>=0;i--) intstack.pop(); for(i=intstack.size()-1;i>=0;i--) intstack.pop(); intstack.push(a[n-1]); d[n-1]=n-1; intstack2.push(d[n-1]); max=sum[n-1]=(d[n-1]-b[n-1]+1)*a[n-1]; for(i=n-2;i>=0;i--) { len=intstack.size()-1; l=0; for(j=len;j>=0;j--) { if(intstack.empty()) { intstack.push(a[i]); d[i]=0; intstack2.push(d[i]); } else if(a[i]<=intstack.top()) { l=1; d[i]=intstack2.top(); top=intstack2.top(); intstack.pop(); intstack2.pop(); if(intstack.empty()) { intstack.push(a[i]); intstack2.push(d[i]); } } else { if(l==0) { d[i]=i; intstack.push(a[i]); intstack2.push(d[i]); } else { d[i]=top; intstack.push(a[i]); intstack2.push(top); } } } sum[i]=(d[i]-b[i]+1)*a[i]; if(sum[i]>=max) max=sum[i]; } printf("%I64d\n",max); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator