| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
看清楚了,有50000个数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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator