inlinevoidmove( int n , char a , char b , char c ) //将a上的n块借助b移动到c上去 { staticint cnt = 1 ; if ( n == 1 ) { printf("step %3d : move %c to %c\n", cnt++ , a , c ) ; return ; } move ( n-1 , a , c , b ) ; printf("step %3d : move %c to %c\n", cnt++ , a , c ) ; move ( n-1 , b , a , c ) ; }
intmain() { printf("Input the number of diskes you want to move:") ; scanf("%d",&n) ; move ( n , 'a' , 'b' , 'c' ) ; return0 ; }
voidquicksort( int b[] , int l , int r ) { re int i = l , j = r , key ; if ( l == r ) return ; else key = b[i] ; while ( i < j ) { while ( ( i < j ) && b[j] > key ) j-- ; if( i < j ) b[i++] = b[j] ; while ( ( i < j ) && b[i] <= key ) i++ ; if( i < j ) b[j--] = b[i] ; } b[i] = key ; sort( b , l , i-1 ) ; sort( b , i+1 , r ) ; }
intmain() { quicksort( a , 0 , cnt - 1 ) ; for ( re int i = 0 ; i < cnt ; i++ ) printf("%d " , a[i]) ; return0 ; } // code by dekrt , 2021 - 11 - 20
intsearch( int b[] , int l , int r , int key ) { if( l == r ) return l ; re int mid = l + ( ( r - l ) >> 1 ) ; if( b[mid] <= key ) return search( b , mid + 1 , r , key ) ; elsereturn search ( b , l , mid - 1 , key ) ; }
voidbinary_insertsort( int b[] , int n ) { for ( re int i = 1 ; i < n ; i++ ) { re int tmp = b[i] , l = 0 , r = i - 1 , mid ; while ( l <= r ) { mid = ( l + r) >> 1 ; if( b[mid] <= tmp ) l = mid + 1 ; else r = mid - 1 ; } re int j ; for ( re int j = i - 1 ; j >= mid ; j-- ) b[j+1] = b[j] ; b[l] = tmp ; } }
intmain() { for ( re int i = 1 ; i < cnt ; i++ ) { int tmp = search ( a , 0 , i - 1 , a[i] ) ; for ( re int j = i - 1 ; j >= tmp ; j-- ) a[j+1] = a[j] ; a[tmp] = a[i] ; } for ( re int i = 0 ; i < cnt ; i++ ) printf("%d " , a[i]) ; return0 ; } // code by dekrt , 2021 - 11 - 20
voiddfs( int cnt , int x , int y ) { if ( cnt > n * n ) return ; a[x][y] = cnt ; int xx = x + 1 , yy = y + 1 ; if( xx > n ) xx -= n ; if( yy > n ) yy -= n ; if( a[xx][yy] == 0 ) dfs ( cnt + 1 , xx , yy ) ; else dfs( cnt + 1 , x , y - 1 ) ; }
intmain() { printf("Please input 'n' to start the program:\n") ; scanf ("%d" , &n ) ; dfs( 1 , ( n + 1 ) >> 1 , n ) ; for ( re int i = n ; i >= 1 ; i-- , putchar('\n') ) for( re int j = 1 ; j <= n ; j++ ) printf("%3d " , a[j][i] ) ; return0 ; } // code by dekrt , 2021 - 11 - 20