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

Re:请发给我一个吧,我写了 1500B的代码才 109ms的,想学学高效算法

Posted by wr at 2005-08-24 22:49:26 on Problem 2452
In Reply To:请发给我一个吧,我写了 1500B的代码才 109ms的,想学学高效算法 Posted by:sunmoonstar_love at 2005-08-24 01:43:26
int da[50001];
int main()
{
	int i,j,m,n,p;
	while (scanf("%d",&n)!=EOF) {
		for (i=1;i<=n;i++) scanf("%d",&da[i]);
		for (i=1,m=-1;i+m<n;i++) { //加了"+m"二个字符,汗..
			p=i;
			for (j=i+1;j<=n;j++) 
				if (da[j]<da[i]) break;
				else if (da[j]>da[p]) p=j; 
				if (p-i>m) m=p-i;
		}
		if (m==0) m=-1;
		printf("%d\n",m);
	}
}

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