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 |
这是本人的代码 O(N) 供大家批评!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator