Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.01.17 - [BOJ] 11729. 하노이 탑 이동 순서 #195

Closed
suhyunsim opened this issue Jan 17, 2022 · 0 comments
Closed

22.01.17 - [BOJ] 11729. 하노이 탑 이동 순서 #195

suhyunsim opened this issue Jan 17, 2022 · 0 comments
Assignees
Labels
성공 맞은 문제 실버 BOJ - 실버 재귀

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Jan 17, 2022

문제

핵심 아이디어

  • 1 + 2 + 3 == 6
  • 1 << n - 1 == 2^(n - 1)

어려운 점, 실수

  • 시간초과 -> StringBuilder로 풀이

풀이

package main.java.com.poogle.BOJ.Q11729;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println();
        calculate(1, 3, n);
    }

    private static void calculate(int a, int b, int n) {
        if (n == 1) {
            System.out.println(a + " " + b);
            return;
        }
        calculate(a, 6 - a - b, n - 1);
        System.out.println(a + " " + b);
        calculate(6 - a - b, b, n - 1);
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 실버 BOJ - 실버 재귀 labels Jan 17, 2022
@suhyunsim suhyunsim added this to the 1월 3주 차 milestone Jan 17, 2022
@suhyunsim suhyunsim self-assigned this Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 실버 BOJ - 실버 재귀
Projects
None yet
Development

No branches or pull requests

1 participant