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

Why wa?Help!!!

Posted by suying at 2008-09-21 10:48:13 on Problem 3298
Why wa?Help!!!
#include<iostream>
using namespace std;
int main()
{
	unsigned m,n,i;
	cin>>m;
	unsigned a[30040];
	while(m--){
        cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		unsigned j,max=1,t,s;
		if(n==1) cout<<1<<endl;
		else{
		for(i=0;i<n-1;i++)
		{
			t=1,s=-1;
		     if(a[i] > a[i+1])
			 {
               s = 1;
               t ++;
			 
             for(j=i+1;j<n-1;j++)
			 {
                      if( s==1&&a[j]<a[j+1] || s==-1&&a[j]>a[j+1] )
					  {
                                t ++;
                                s*= -1;
					  }
					  else break;
			 }
                 if(t > max) max = t;
			 }
			 
		}
		  cout<<max<<endl;
		}
	}
		return 0;
	}
		
lp!!!

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