매일코테

백준 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
반응형

'매일코테' 카테고리의 다른 글

백준 10단계 no.3  (0) 2022.07.26
백준 10단계 no.1  (0) 2022.07.26
백준 9단계 no.3  (0) 2022.07.25
백준 9단계 no.1  (0) 2022.07.25
백준 9단계 no.2  (0) 2022.07.25