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:给点测试数据把,不知道错哪了

Posted by phoenixzz at 2009-01-14 22:37:36 on Problem 2452
In Reply To:给点测试数据把,不知道错哪了 Posted by:foreverlin at 2008-12-27 21:17:11
> 我的思路,线性扫秒,保存当前的最大和最小,以及他们的下标,并计算出当前距离,如果遇到一个比max大的,那么将起赋为最小同时改变下标,动态的更新最长距离
> #include<iostream>
> using namespace std;
> int a[50001];
> int main()
> {
>     int n,i,max,min,sum,len,ti,tj;
>     while(scanf("%d",&n)!=EOF)
>     {
>           for(i=1;i<=n;i++)
>           {
>               scanf("%d",&a[i]);             
>               }
>           max=-999999999;
>           min=999999999;
>           ti=1;tj=1;
>           len=0;
>           sum=0;   
>           for(i=1;i<=n;i++)
>           {
> //              cout<<"case:"<<i<<endl;             
>               if(a[i]>max)
>               {
>                  max=a[i];
>                  tj=i;         
>                  }
>               if(a[i]<min)
>               {
>                  min=a[i];
>                  ti=i;         
>                  }
>               len=tj-ti;
>               if(len>sum)sum=len;   
>               if(a[i]<max)
>               {         
>                  min=a[i];
>                  ti=i;
>                  max=a[i];tj=i;         
>                  }
> //              cout<<"i="<<ti<<" j="<<tj<<endl;
> //              cout<<"min="<<min<<" max="<<max<<endl;
> //              system("pause");                            
>               }
>           if(sum==0)printf("-1\n");
>           else printf("%d\n",sum);                         
>           }
>     return 0;
>     }


6
1 3 5 2 4 6

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