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

这是本人的代码 O(N) 供大家批评!

Posted by hahanv at 2007-03-28 21:34:27 on Problem 2470
#include <stdio.h>

int isAmbig ( long a[] , long index )
{
	int i = 1 ;

	for ( i = 1 ; i <= index && a[a[i]] == i ; ++i )  ;
	if ( i == index + 1 ) return 1 ;
	
	return 0 ;
}

int main ( void )
{
	long cases ;
	long a[150000] ;
	long i = 0 , index = 0 ;

	while ( 1 )    {
		i = 1 ;
		scanf ( "%li" , &cases ) ;

		if ( cases == 0 )
			break ;

		while ( cases )   {
			scanf ( "%li" , &a[i] ) ;
			++i ;
			--cases ;
		}
		index = i - 1 ;

		if ( isAmbig ( a , index ))
			printf ( "ambiguous\n" ) ;
		else
			printf ( "not ambiguous\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