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

高手帮忙看看算法错在哪里

Posted by egmna at 2005-08-19 12:57:17 on Problem 2452
#include <iostream>
using namespace std;

long sti[50001];
long low[50001];

int main()
{
	long i,n;
	
	while(cin>>n)
	{
		cin>>sti[1];
		low[1]=1;
		for(i=2;i<=n;i++)
		{
			cin>>sti[i];
			low[i]=i;
			while(low[i]>=2&&sti[i]>sti[low[i]-1]&&sti[low[i]]>sti[low[low[i]-1]])
				low[i]=low[low[i]-1];
		}
		long max=0;
		for(i=1;i<=n;i++)
			if(i-low[i]>max) max=i-low[i];
		if(max) cout<<max<<endl;
		else cout<<"-1"<<endl;
	}
	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