From 1b8243e217b8007ef461503ef9a0a1436df29004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Tue, 14 Oct 2025 21:37:37 +0900 Subject: [PATCH] =?UTF-8?q?[20251014]=20BOJ=20/=20G5=20/=20=ED=95=98?= =?UTF-8?q?=EB=85=B8=EC=9D=B4=20=ED=83=91=20/=20=EA=B0=95=EC=8B=A0?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\205\270\354\235\264 \355\203\221.md" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "ksinji/202510/14 BOJ \355\225\230\353\205\270\354\235\264 \355\203\221.md" diff --git "a/ksinji/202510/14 BOJ \355\225\230\353\205\270\354\235\264 \355\203\221.md" "b/ksinji/202510/14 BOJ \355\225\230\353\205\270\354\235\264 \355\203\221.md" new file mode 100644 index 00000000..c620a9be --- /dev/null +++ "b/ksinji/202510/14 BOJ \355\225\230\353\205\270\354\235\264 \355\203\221.md" @@ -0,0 +1,31 @@ +```java +import java.io.*; +import java.math.BigInteger; + +public class Main { + static int N; + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + BigInteger moves = BigInteger.valueOf(2).pow(N).subtract(BigInteger.ONE); + sb.append(moves).append('\n'); + + if (N <= 20) { + hanoi(N, 1, 3, 2); + } + + System.out.print(sb.toString()); + } + + // N개를 from -> to + static void hanoi(int N, int from, int to, int temp) { + if (N == 0) return; + hanoi(N - 1, from, temp, to); // N-1개를 출발 -> 보조 기둥으로 옮김 + sb.append(from).append(' ').append(to).append('\n'); // 출발 -> 목적 기둥으로 남은 원판(젤 큰 거) 옮김 + hanoi(N - 1, temp, to, from); // N-1개를 보조 -> 목적 기둥으로 옮김 + } +} +```