[BOJ] 11729번 : 하노이 탑 이동순서

2024. 8. 15. 19:56Algorithm

1. problem :

https://www.acmicpc.net/problem/11729

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;

void hanoi(int a, int b, int n) {
	if (n == 1) {
		cout << a << ' ' << b << '\n';
		return;
	}
	hanoi(a, 6 - a - b, n - 1);
	cout << a << ' ' << b << '\n'; 
	hanoi(6 - a - b, b, n - 1);
}
int main(void) {
	int n;
	cin >> n;
	cout << (1 << n) - 1 << '\n';
	hanoi(1, 3, n);
	return 0;
}

< source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x0B/solutions/11729.cpp>

 

basic-algo-lecture/0x0B/solutions/11729.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

외우자

'Algorithm' 카테고리의 다른 글

[BOJ] 1780번 : 종이의 개수  (0) 2024.08.15
[BOJ] 17478 : 재귀함수가 뭔가요?  (0) 2024.08.15
[BOJ] 2206번 : 벽 부수고 이동하기  (0) 2024.08.15
[BOJ] 1629번 : 곱셈  (0) 2024.08.15
[BOJ] 5427번 : 불  (0) 2024.08.14