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

看清楚了,有50000个数

Posted by frkstyc at 2007-04-13 22:49:26 on Problem 2479
In Reply To:就两个循环怎么还超时呢,测试数据都对啊~ Posted by:FantasyTwins at 2007-04-13 22:24:10
> 太郁闷了!!
> #include <stdio.h>
> 
> int main()
> {
> 	int n,i,j,max,preMax,curMax,p,n1,n2;
> 	int a[1000];
> 	int l[1000];
> 	int m[1000];
> 
> 	scanf("%d",&n);
> 
> 	while (n>0)
> 	{
> 		scanf("%d",&i);
> 		
> 		for (j=0;j<i;j++)
> 		{
> 			scanf("%d",&a[j]);
> 		}
> 	
> 		curMax=0;
> 		preMax=-2000000000;
> 	
> 		p=0;
> 
> 		while (p<i)
> 		{
> 			curMax+=a[p];
> 
> 			if (curMax>preMax)
> 			{
> 				preMax=curMax;
> 			}
> 
> 			if (curMax<0)
> 			{
> 				curMax=0;
> 			}
> 
> 			l[p]=preMax;
> 			p++;
> 		}
> 
> 
> 		max=m[1]=l[0]+l[1];
> 
> 
> 		for (p=2;p<i;p++)
> 		{
> 			n1=m[p-1]+a[p];
> 			n2=l[p-1]+a[p];
> 			
> 			if (n1<n2)
> 				n1=n2;
> 
> 			if (n1>max)
> 				max=n1;
> 		}
> 
> 		printf("%d\n",max);
> 		n--;
> 	}
> 
> 	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