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
|
#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]); }
|