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

不会rmq,暴力672ms ac 付代码

Posted by hitfrank at 2010-05-16 13:21:56 on Problem 2452
#include <iostream>
using namespace std;
int num[50001];

int main()
{
	int count;
	while(cin>>count)
	{
		int i=0;
		int res=0;
		int index;
		for(int j=0;j<count;j++)
			scanf("%d",num+j);

		while(i<count-1)
		{
			int mymax=num[i];
			index=i;
			int j;
			for(j=i+1;j<count;j++)
			{
				if(num[j]<=num[i])
				{
					if(index==i)
						i++;
					else
						i=index+1;
					break;
				}
				else if(num[j]<=mymax)
				{
					if(j==count-1)
						i=index+1;
					continue;
				}
				else
				{
					if(j-i>res)
						res=j-i;
					mymax=num[j];
					index=j;
				}
				if(j==count-1)
					i=index+1;
			}
		}
		if(res==0)
			printf("-1\n");
		else
			printf("%d\n",res);
	}
}

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