From 7bc9ac77ecdf9f4ecde0254c9ae95ef9d6a212e0 Mon Sep 17 00:00:00 2001 From: Minsung_Kang Date: Thu, 15 Feb 2024 22:35:35 +0900 Subject: [PATCH] =?UTF-8?q?2024-02-15=20=ED=95=98=EB=85=B8=EC=9D=B4=20?= =?UTF-8?q?=ED=83=91=20=EC=9D=B4=EB=8F=99=20=EC=88=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rivkms/README.md | 1 + rivkms/Recursion/11729.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rivkms/Recursion/11729.cpp diff --git a/rivkms/README.md b/rivkms/README.md index a2c6ea2..2447a7b 100644 --- a/rivkms/README.md +++ b/rivkms/README.md @@ -3,4 +3,5 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2024.02.12 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/5) | +| 2차시 | 2024.02.15 | Recursion | [하노이 탑 이동 순서](https://www.acmicpc.net/problem/11729) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/8) | --- diff --git a/rivkms/Recursion/11729.cpp b/rivkms/Recursion/11729.cpp new file mode 100644 index 0000000..7b059e8 --- /dev/null +++ b/rivkms/Recursion/11729.cpp @@ -0,0 +1,30 @@ +#include +#include +using namespace std; + +vector> box; + +void func(const int & start, const int & center, const int & end, const int & n){ + if(n==1){ + box.push_back(pair (start, end)); + return; + } + func(start, end, center, n-1); + box.push_back(pair (start, end)); + func(center, start, end, n-1); + + return; +} + +int main(){ + ios_base::sync_with_stdio(false); cin.tie(NULL); + int n, a = 0; + cin >> n; + func(1,2,3,n); + cout << box.size() << "\n"; + for(pair i : box){ + cout << i.first << " " << i.second << "\n"; + } + + return 0; +} \ No newline at end of file