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

感觉算法不是很难,为什么总是wa?

Posted by Gump at 2005-09-14 11:50:01 on Problem 1363
# include<iostream.h>
int yes_or_no( int [], int );
int main() 
{
	int num,Array[1000],n;
	int output_instruct[1000],count=0;
	cin>>num;
	while( num != 0 )
	{
		cin>>n;
		while( n!=0 )
		{ 
		    Array[0]=n;
			for(int i=1; i<num; i++ )
			{
				cin>>n; 
				Array[i]=n;
			}
		 
			output_instruct[count++] = yes_or_no( Array, num );
			
			cin>>n;
		}
	    output_instruct[count++]=2;
		cin >> num;
	}

	for( int i=0; i<count-1; i++ )
	{
		switch( output_instruct[i] )
		{
		case 1: cout<<"Yes"<<endl; break;
		case 0: cout<<"No"<<endl; break;
		case 2: cout<<endl;
		}
	}
	return 0;
	 
}

int  yes_or_no( int *a, int length )	
{
	int i,j,tem1,tem2;
	bool right_array;
	while(1)
	{
		for( i=0; i<length; i++ )
			if( a[i] != 0 )
				break;
		
		if( i== length ) 
			break;
		
		if( i== length-1 )
		{
			 
			a[i]=0;
			break;
		}

		tem1= a[i];
		 
		tem2= tem1;
		a[i]=0;
		
        
		right_array = true;
		for( j=i+1; j<length; j++ )
		{
			if( a[j] < tem2 && a[j] != 0 )
			{
				if( a[j] < tem1 )
				{
					tem1 = a[j];
				 
					a[j] = 0;
					 
				}
				else
				{
					right_array= false;
				 
					break;
				}
			}
		}
		if( right_array== false )
			break;
	}
	
	for( i=0; i<length; i++ )
		if( a[i] != 0 )
			break;
		 
	
	if( i == length )
		return 1;
	else
		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