매일코테
백준 9단계 no.5
공주맛밤
2022. 7. 26. 11:08
import java.io.*;
import java.util.*;
public class Main {
private static final StringBuilder output = new StringBuilder();
static void move(int no, int x, int y) {
if (no > 1)
move(no - 1, x, 6 - x - y);
output.append(x).append(" ").append(y).append("\n");
if (no > 1)
move(no-1,6-x-y,y);
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
System.out.println((int) Math.pow(2, n)-1);
move(n, 1,3);
System.out.println(output);
}
}
시간을 줄이는 건 언제나 어려워
+ 하노이 탑 이해하기 : https://tnut0305.tistory.com/62
728x90
반응형