23:51不会真的有在线的帮我吧?
查看原帖
23:51不会真的有在线的帮我吧?
665669
_cxy_楼主2022/3/5 23:51

某垃圾写不出了,求大佬拔刀相助!!!

#include <iostream>
using namespace std;
int N, X[45], Y[45], show[3][45], ans;

bool check_queen(int x, int y, int s) {
	int k;
	for (k = 0; k < s; k++) {
		if (x == X[k] || y == Y[k]  )
			return false;
		else if ((x - 1 == X[k] && y - 1 == Y[k]) || (x + 1 == X[k] && y + 1 == Y[k]))
			return false;
	}
	return true;
}

int dfs(int step) {
	if (step == N) {
		ans++;
		/*求如何更新show数组*/
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (check_queen(i, j, step)) {
				dfs(step + 1);
			}
		}
	}
}

int main() {
	cin >> N;
	dfs(0);
	cout << ans;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < N; j++)
			cout << show[i][j];
		cout << endl;
	}
}
2022/3/5 23:51
加载中...