Skip to content

Commit

Permalink
Merge pull request #41 from AlgoLeadMe/12-oesnuj
Browse files Browse the repository at this point in the history
12-oesnuj
  • Loading branch information
oesnuj authored Sep 4, 2024
2 parents 595b53f + fc20d42 commit 15e0658
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
| 9์ฐจ์‹œ | 2024.05.30 | ๊ตฌํ˜„ | [๋น™๊ณ ](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) |
| 10์ฐจ์‹œ | 2024.07.04 | ๊ตฌํ˜„ | [์ƒ์–ด์ดˆ๋“ฑํ•™๊ต](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) |
| 11์ฐจ์‹œ | 2024.07.18 | ์ด๋ถ„ ํƒ์ƒ‰ | [๋žœ์„  ์ž๋ฅด๊ธฐ](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) |
| 12์ฐจ์‹œ | 2024.07.24 | ์žฌ๊ท€ | [ํ•˜๋…ธ์ด ํƒ‘](https://www.acmicpc.net/problem/1914) | [#41](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/41) |
---
33 changes: 33 additions & 0 deletions oesnuj/์žฌ๊ท€/1914.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

void RecurMoveDisks(int n, int from, int temp, int to) {
if (n == 0) return;
//n-1๊ฐœ์˜ ์›ํŒ์œผ๋กœ temp๋กœ ์˜ฎ๊ธด๋‹ค.
RecurMoveDisks(n - 1, from, to, temp);

//๋‚จ์€ 1๊ฐœ์˜ ์›ํŒ์œผ๋กœ to๋กœ ์˜ฎ๊ธด๋‹ค. <- ์ด๋•Œ ์˜ฎ๊ธฐ๋Š” ๊ณผ์ • ์ถœ๋ ฅ
cout << from << " " << to << "\n";

//temp์— ์žˆ๋˜ n-1๊ฐœ์˜ ์›ํŒ์„ n-1๊ฐœ๋กœ ์˜ฎ๊ธด๋‹ค.
RecurMoveDisks(n - 1, temp, from, to);
}

int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;

//2์˜ n์ œ๊ณฑ -1 ์ถœ๋ ฅํ•˜๊ธฐ
string cnt = to_string(pow(2, n));
int x = cnt.find('.');
cnt = cnt.substr(0, x);
cnt[cnt.length() - 1] -= 1;
cout << cnt << "\n";

//์กฐ๊ฑด์— ๋งž๋Š” ๊ฒฝ์šฐ์—๋งŒ ์žฌ๊ท€๋ฅผ ๋Œ๋ฆฐ๋‹ค.
if (n <= 20) RecurMoveDisks(n, 1, 2, 3);
return 0;
}

0 comments on commit 15e0658

Please sign in to comment.