Test instructions: Give you a classic Hanoi recursive program and ask you at least a few steps to make the same number of plates on the three pillars. (Ensure that the initial plate number can be divisible by 3)
Law: ANS (n) =2^ (2*n/3-1) +t (N/3).
T (1) =0.
T (n) =
T (n-1) +1,n is even
T (n-1) *4+2,n is odd.
Java file read and write mainly the following two methods, the second, the output format more arbitrary, more practical:
import java.util.*;import java.io.*;import java.math.*;p ublic class Main{ public static void Main (string[] argc) {biginteger[] t=new biginteger[305]; Biginteger[] pw=new biginteger[305];t[1]=biginteger.zero;for (int i=2;i<=100;++i) {if (i%2==0) {T[i]=t[i-1].add ( Biginteger.one);} Else{t[i]=t[i-1].multiply (biginteger.valueof (4l)). Add (Biginteger.valueof (2l));}} pw[0]=biginteger.one;for (int i=1;i<=300;++i) {pw[i]=pw[i-1].multiply (biginteger.valueof (2l));} Scanner cin = new Scanner (system.in); try{cin=new Scanner (New FileInputStream ("Input.txt"));} catch (Exception e) {}int n=cin.nextint (); Cin.close ();/*pw[2*n/3-1].add (T[N/3]). toString () */file file=new File (" Output.txt "), Try{bufferedwriter bf=new bufferedwriter (new PrintWriter (file)); Bf.append (Pw[2*n/3-1].add (T[N/3)). ToString ()); Bf.close ();} catch (Exception e) {}}}
Import java.util.*;import java.io.*;import java.math.*;p ublic class main{public static void Main (string[] argc) { Biginteger[] T=new biginteger[305]; Biginteger[] pw=new biginteger[305];t[1]=biginteger.zero;for (int i=2;i<=100;++i) {if (i%2==0) {T[i]=t[i-1].add ( Biginteger.one);} Else{t[i]=t[i-1].multiply (biginteger.valueof (4l)). Add (Biginteger.valueof (2l));}} pw[0]=biginteger.one;for (int i=1;i<=300;++i) {pw[i]=pw[i-1].multiply (biginteger.valueof (2l));} Scanner cin = new Scanner (system.in); try{cin=new Scanner (New FileInputStream ("Input.txt"));} catch (Exception e) {}int n=cin.nextint (); Cin.close ();/*pw[2*n/3-1].add (T[N/3]). toString () *///file file=new File (" Output.txt "); Try{filewriter fw = new FileWriter (" Output.txt ", true); PrintWriter cout = new PrintWriter (FW); Cout.println (Pw[2*n/3-1].add (T[N/3)); Cout.flush ();//bufferedwriter bf=new BufferedWriter (new PrintWriter),//bf.append (Pw[2*n/3-1].add (T[N/3]). toString ());//bf.close (); catch (Exception e) {}}}
"Java" "Find the Law" Gym-101243b-hanoi Tower