Skip to content

Commit

Permalink
2024-02-15 하노이 탑 이동 순
Browse files Browse the repository at this point in the history
  • Loading branch information
rivkms committed Feb 15, 2024
1 parent b705dab commit 7bc9ac7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions rivkms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
30 changes: 30 additions & 0 deletions rivkms/Recursion/11729.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <vector>
using namespace std;

vector<pair<int, int>> box;

void func(const int & start, const int & center, const int & end, const int & n){
if(n==1){
box.push_back(pair<int, int> (start, end));
return;
}
func(start, end, center, n-1);
box.push_back(pair<int, int> (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<int, int> i : box){
cout << i.first << " " << i.second << "\n";
}

return 0;
}

0 comments on commit 7bc9ac7

Please sign in to comment.