标签:
#include<iostream> using namespace std; int C[8]; int res = 0;//多少组解 void EightQueen(int n,int curr) { if (curr == n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (C[i] == j) cout << "Q "; else cout << "* "; } cout << endl; } return; } else { for (int i = 0; i < n; i++) { C[curr] = i;//第curr行放在第i列上 bool flag = true; for (int j = 0; j < curr; j++) { if (C[curr] == C[j] || curr - C[curr] == j - C[j] || curr + C[curr] == j + C[j]) { flag = false; break; } } if (flag) { EightQueen(n, curr + 1); } } } } int main() { EightQueen(8,0); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u014338577/article/details/47978495