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

Time Lapse :None

11729.cpp

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
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// main.cpp
// Algo
//
// Created by SummerFlower on 25/09/2019.
// Copyright © 2019 SummerFlower. All rights reserved.
//
// c++_algo.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
//

#include <stdio.h>


int process[2000000][2];
int N, cnt;

void topmove(int n, int from, int to)
{
int left = 6-from-to;
if(n==1)
{
process[cnt][0] = from;
process[cnt++][1] = to;
}
else
{
topmove(n-1,from,left);
process[cnt][0] = from;
process[cnt++][1] = to;
topmove(n-1,left,to);
}

}
int main(void)
{
scanf("%d",&N);
topmove(N,1,3);
printf("%d\n",cnt);
for(int i = 0;i<cnt;i++)
printf("%d %d\n",process[i][0], process[i][1]);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/11729/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.