Cod sursa(job #3237165)

Utilizator szabelrAbel Szanto szabelr Data 5 iulie 2024 19:43:14
Problema Problema Damelor Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.58 kb
// sakk.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
void bejelol ( int n, int x, int y , int a[20][20])
{
	int x1, y1;
	for (int i = 1; i <= n;  i++) {
		a[x][i] = 1;
	}
	for (int i = 1; i <= n; i++) {
		a[i][y] = 1;
	}
	//jobbra fel
	x1 = x;
	y1 = y;
	while (x1 <= n and x1 >= 1 and y1 <= n and y1 >= 1) {
		a[x1][y1] = 1;
		x1++;
		y1++;
	}
	//balra fel
	x1 = x;
	y1 = y;
	while (x1 <= n and x1 >= 1 and y1 <= n and y1 >= 1) {
		a[x1][y1] = 1;
		x1++;
		y1--;
	}
	//jobbra le
	x1 = x;
	y1 = y;
	while (x1 <= n and x1 >= 1 and y1 <= n and y1 >= 1) {
		a[x1][y1] = 1;
		x1--;
		y1++;
	}
	//balra le
	x1 = x;
	y1 = y;
	while (x1 <= n and x1 >= 1 and y1 <= n and y1 >= 1) {
		a[x1][y1] = 1;
		x1--;
		y1--;
	}
	/*kiiras
	for (int i = n; i >= 1; i--) {
		for (int y = 1; y <= n; y++) {
			cout << a[i][y]<<" ";
		}
		cout << endl;
	}*/
}


void gen(int n, int szint, int& mo, int mego[20]) {
	int a[20][20]{ 0 };
	if (szint <= n){ 
		for (int i = 1; i <= szint - 1; i++) {
			bejelol(n, i, mego[i], a);
		}
		for (int i = 1; i <= n; i++) {
			if (a[szint][i] == 0) {
				mego[szint] = i;
				gen(n, szint + 1, mo, mego);
			}
		}
	}
	else {
		if (mo == 0) {
			for (int i = 1; i <= n; i++)
			{
				g << mego[i] << " ";
			}
			g << endl;
		}
		mo++;
	}
}


int main() {
	
	int x, y, n,mo=0;
	int mego[20];
	f >> n;
	int szint = 1;
	gen(n, szint, mo, mego);
	g << mo;
}