본문 바로가기
백준

[11729] 하노이 탑 이동 순서

by Jcoder 2018. 10. 29.


#include <iostream>
using namespace std;
void HanoiTowerMove(int num, int from, int by, int to)
{
if (num == 0) // 이동할 원반의 수가 1개라면
return;
else
{
HanoiTowerMove(num - 1, from, to, by); // 3단계 중 1단계
printf("%d %d\n", from, to); // 3단계 중 2단계
HanoiTowerMove(num - 1, by, from, to); // 3단계 중 3단계
}
}
int main(void)
{
int n;
cin >> n;
cout << (1 << n) - 1 << "\n";
HanoiTowerMove(n, 1, 2, 3);
return 0;
}


'백준' 카테고리의 다른 글

[1436] 영화감독 숌  (0) 2019.01.04
[1977] 완전제곱수  (0) 2019.01.03
[2902] KMP는 왜 KMP일까?  (0) 2018.10.21
[1991] 트리 순회  (0) 2018.10.20
[9252] LCS 2  (0) 2018.10.20