Return to achieve two-dimensional array of non-tree

// do not return the number of two-dimensional array implementation fragrant the 
public
class the Test { public static void main (String [] args) { int n-= 10 ; // return order tree for ( int I = 0; I <n-n-* ; I ++ ) { of System.out.print (String.format ( "% 3D", Resolve (n-, I +. 1)) + "," ); IF ((I +. 1)% n-== 0 ) { the System. Out.println (); } } System.out.println (); } public static int Resolve ( int n-, int X) { if(x < n){ return x; } if(x%n == 0){ return x/n + n - 1; } if((n-1)*n < x && n*n>=x){ return n*(n+2)-1-x; } if(x%n == 1){ return 4*n-x/n-3; } return 4*(n-1) + resolve(n-2, x-x/n*2-n+1); } }

Guess you like

Origin www.cnblogs.com/hjm0928/p/11830533.html