Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一直WA,各位大侠帮忙看看啊~~

Posted by ggzx at 2010-12-15 11:59:15
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator