#include "pch.h"
#include <iostream>
#include <cassert>
 
using namespace std;
 
const int N = 32;
 
struct Vez
{
    int v;    // 0 <= v <= N
    int p[N]; // p[0] dole , ... , p[v-1] vrchol, 
              // p[i] ... { 1, ..., N }
 
};
 
void clear(Vez &A) {
    A.v = 0;
    for (int i = 0; i < N; i++)
        A.p[i] = 0;
}
 
void init(Vez &A) {
    A.v = N;
    for (int i = 0; i < N; i++)
        A.p[i] = (N - i);
}
 
void print(Vez &A) {
    for (int i = 0; i < N; i++) {
        if (i < A.v)
            cout << A.p[i] << " ";
        else
            cout << "  "; 
    }
}
 
void print(Vez &A, Vez &B, Vez &C) {
    print(A);
    cout << " : ";
    print(B); 
    cout << " : ";
    print(C); 
    cout << endl; 
}
 
Vez X, Y, Z;
 
void step1(Vez &A, Vez &B)
{
    assert(A.v != 0);
    assert(B.v < N);
    int d = A.p[A.v - 1];
    A.v--;
    if(B.v != 0){
    int k = B.p[B.v - 1];
    assert(k > d);
    }
    B.v++;
    B.p[B.v - 1] = d;
}
 
void move(Vez &A, Vez &B, Vez &C, int k) {
    //base case
    if (k > 1) move(A, C, B, k - 1);
    step1(A, C);
    // print(X, Y, Z);
    if (k > 1) move(B, A, C, k - 1);
 
}
 
int main()
{
    init(X);
    clear(Y);
    clear(Z);
    // print(X, Y, Z);
    move(X, Y, Z, N);
    print(X, Y, Z);
    cout << "O.K." << endl;
}
 
veze_2019_ut.txt · Last modified: 2019/03/19 10:35 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki