일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 파일시스템 구현
- 그리디알고리즘
- 그리디 알고리즘
- 쓰레드
- 락
- 다이나믹 프로그래밍
- Direct12
- OS
- codility
- 병행성
- 스케줄링
- 컨디션 변수
- 타입 객체
- DirectX12
- 멀티프로세서
- 영속성
- 렌더링 파이프라인
- 백준
- 멀티쓰레드
- directx
- 병행성 관련 오류
- 다이나믹프로그래밍
- 디자인패턴
- I/O장치
- 프로그래머스
- 동적계획법
- 운영체제
- 알고리즘
- DirectX 12
- 자료구조
Archives
- Today
- Total
기록공간
하노이탑(백준-11729) 본문
반응형
#include <iostream>
#include <math.h>
using namespace std;
class CHanoi
{
public:
int GetCount() { return m_nCount; }
public:
void InputCount()
{
cin >> m_nCount;
}
void Solve(int circleCount, int from, int by, int to)
{
if (circleCount == 1)
{
Move(from, to);
}
else
{
// 1번째에서 3번째를 거쳐 2번째로 n-1만큼 옮긴다.
// 나머지 하나를 1번쨰에서 3번째로 옮긴다.
// 2번째에 있는 n-1개를 1번째를 거쳐 3번째로 옮긴다.
Solve(circleCount - 1, from, to, by);
Move(from, to);
Solve(circleCount - 1, by, from, to);
}
}
void Move(int from, int to)
{
cout << from << ' ' << to << endl;
}
void PrintResultCount(int circleCount)
{
cout << (int)pow(2, circleCount) - 1 << endl;
}
private:
int m_nCount = 0;
};
int main()
{
CHanoi h;
h.InputCount();
h.PrintResultCount(h.GetCount());
h.Solve(h.GetCount(), 1, 2, 3);
}
반응형
'Algorithm > 문제' 카테고리의 다른 글
로프 (백준 - 2217번) (0) | 2020.02.08 |
---|---|
회의실배정 (백준 - 1931번) (0) | 2020.02.08 |
동전 0 (백준 - 11047번) (0) | 2020.02.08 |
ATM (백준 - 11399번) (0) | 2020.02.08 |
별찍기 - 10 (백준-2447) (0) | 2019.07.26 |
Comments