#include "pch.h"
#include <iostream>
using namespace std;
 
const int N = 8;
 
int p[N];
 
int cnt = 0;
 
void umisti(int s) {
    for (int i = 0; i < N; i++) {
        bool collision = false;
        for (int v = 1; v <= s && !collision; v++) {
            if (p[s - v] == i || p[s-v] == i-v || p[s-v] == i+v) collision = true;
        }
        if (!collision) {
            p[s] = i;
            if (s < N - 1)
                umisti(s + 1);
            else {
                for (int j = 0; j < N; j++) {
                    cout << p[j] << " ";
                }
                cnt++;
                cout << " ... " << cnt << endl;
            }
        }
    }
}
 
int main()
{
    for (int i = 0; i < N; i++) p[i] = -1;
 
    umisti(0);
 
    cout << "O.K." << endl; 
}
 
dama_2019_ut.txt · Last modified: 2019/03/26 13:46 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