过了,但是不明白为什么N=4时要和其他情况不同
查看原帖
过了,但是不明白为什么N=4时要和其他情况不同
871649
kkkllj楼主2023/11/4 15:33
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>

using namespace std;

int N;
int qz[103];

void print_qp()
{
    for (int i = 1; i <= 2 * N + 2; i++)
    {
        switch (qz[i])
        {
        case 1:
            cout << 'o';
            break;
        case 0:
            cout << '*';
            break;
        case -1:
            cout << '-';
            break;
        }
    }
    cout << endl;
    return;
}

// 1白 0黑 -1空
void f(int cur_n)
{
    if (cur_n == 0)
        return;
    if (cur_n >= 4)
    {
        swap(qz[cur_n], qz[cur_n * 2 + 1]);
        swap(qz[cur_n + 1], qz[cur_n * 2 + 2]);
        print_qp();

        if (cur_n == 1)
            return;
        if (cur_n != 4)
        {
            swap(qz[cur_n], qz[cur_n * 2]);
            swap(qz[cur_n + 1], qz[cur_n * 2 - 1]);
        }
        else
        {
            swap(qz[cur_n], qz[cur_n * 2]);
            swap(qz[cur_n + 1], qz[cur_n * 2 + 1]);
        }
        print_qp();
        f(cur_n - 1);
    }
    else
    {
        swap(qz[cur_n], qz[cur_n * 2 + 2]);
        swap(qz[cur_n - 1], qz[cur_n * 2 + 3]);
        print_qp();

        if (cur_n == 1)
            return;
        swap(qz[cur_n - 1], qz[cur_n * 2 + 1]);
        swap(qz[cur_n], qz[cur_n * 2 + 2]);
        print_qp();

        swap(qz[1], qz[7]);
        swap(qz[2], qz[8]);
        print_qp();
        return;
    }
}

int main(int argc, char const *argv[])
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        qz[i] = 1;
    }
    qz[2 * N + 1] = -1;
    qz[2 * N + 2] = -1;

    print_qp();
    f(N);

    return 0;
}
```
2023/11/4 15:33
加载中...