05-18 00:26
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- X.org
- 셀레니움
- Binary Search
- BFS
- Inheritance
- Operator
- preprocessing
- Physical Scheme
- descriptive statistics
- Mac
- Polymolphism
- selenium
- 자바
- External Scheme
- 백준
- X윈도우
- Java
- literal
- Unity
- python
- Reference Type
- 리눅스 마스터 1급
- Entity Set
- Entity
- systemd
- OOP
- Class
- 리눅스
- spring
- dbms
Archives
- Today
- Total
Byeol Lo
N11729 - 하노이 탑 이동 순서 본문
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.*;
public class Main {
private static final BufferedWriter BW = new BufferedWriter(new OutputStreamWriter(System.out));
private static final StringBuffer SB = new StringBuffer();
private static Scanner SC = new Scanner(System.in);
public static void main(String[] args) throws IOException {
solution(SC.nextInt());
BW.write(SB.toString());
BW.close();
}
private static void solution(int n) {
SB.append((int) Math.pow(2, n)-1).append("\n");
hanoi(n, 1, 3);
}
private static void hanoi(int cnt, int move, int to) {
if(cnt == 1) SB.append(move).append(" ").append(to).append("\n");
else {
hanoi(cnt-1, move, 6-move-to);
hanoi(1, move, to);
hanoi(cnt-1, 6-move-to, to);
}
}
}
'Algorithm > DevideConquer & Recursion' 카테고리의 다른 글
N4779 - 칸토어 집합 (0) | 2023.12.11 |
---|---|
N2447 - 별 찍기 - 10 (0) | 2023.12.11 |
Comments