八皇后问题
来源:互联网 发布:防抖插件mac 编辑:程序博客网 时间:2024/06/01 10:20
代码:
#include <iostream>using namespace std;//八皇后void eightQueue(int* colunmnIndex, int k ,int length){ if (k == length) { for (int i = 0 ; i < length; i++) { for (int j = i + 1; j < length; j++) { if ((i - j == colunmnIndex[i] - colunmnIndex[j]) || (j - i == colunmnIndex[i] - colunmnIndex[j])) return; } } for (int i = 0; i < length; i++) cout << colunmnIndex[i]; cout << " "; } else { for (int m = k; m < length; m++) { int temp = colunmnIndex[m]; colunmnIndex[m] = colunmnIndex[k]; colunmnIndex[k] = temp; eightQueue(colunmnIndex, k+1, length); temp = colunmnIndex[m]; colunmnIndex[m] = colunmnIndex[k]; colunmnIndex[k] = temp; } }}void eightQueue(int* colunmnIndex, int length){ if (colunmnIndex == nullptr) return; int i = 0; eightQueue(colunmnIndex, i, length);}int main(){ int colunmnIndex[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; int length = sizeof(colunmnIndex) / sizeof(colunmnIndex[0]); eightQueue(colunmnIndex, length); cout << endl; system("pause"); return 0;}
测试:
0 0
- 八皇后 n皇后 问题
- 八皇后N皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题(2)
- 八皇后问题(3)
- 八皇后问题
- 八皇后问题程序
- 浅谈八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题求解
- 八皇后问题
- 八皇后问题
- 八皇后问题
- redis.clients.jedis.exceptions.InvalidURIException: Cannot open Redis connection due invalid URI
- [Android 源码分析] HandlerThread
- Javasript实现照片墙
- android EditText inputType 大全
- git复习
- 八皇后问题
- iptables命令格式
- CentOS的自动化安装光盘制作 (详细流程)
- 机器学习之多变量线性回归(Linear Regression with multiple variables)
- Arduino Star Otto(STM32F469)
- iOS 多层级列表的实现原理
- 日请求亿级的QQ会员AMS平台PHP7升级实践
- 【C# MVC工具类】DataSet/DataTable 与Xml文件的互相转化
- eclipse下maven使用及tomcat调试manven程序