ZZY的八皇后
来源:互联网 发布:it程序员学徒干什么的 编辑:程序博客网 时间:2024/05/16 00:37
#include<iostream>
#include<iostream>
using namespace std;
int a[80],b[80],ans,c[80],i,n,j;
void f(int i,int n){
if(i>n){
ans++;
return;
}
for(int j=1;j<=n;j++){
if(!a[j]&&!b[i+j]&&!c[i-j+8]){
a[j]=true;b[i+j]=true;c[i-j+8]=true;
f(i+1,n);
a[j]=false;b[i+j]=false;c[i-j+8]=false;
}
}
}
int main(){
cin>>n;
f(1,n);
cout<<ans;
}
#include<iostream>
using namespace std;
int a[80],b[80],ans,c[80],i,n,j;
void f(int i,int n){
if(i>n){
ans++;
return;
}
for(int j=1;j<=n;j++){
if(!a[j]&&!b[i+j]&&!c[i-j+8]){
a[j]=true;b[i+j]=true;c[i-j+8]=true;
f(i+1,n);
a[j]=false;b[i+j]=false;c[i-j+8]=false;
}
}
}
int main(){
cin>>n;
f(1,n);
cout<<ans;
}
0 0
- ZZY的八皇后
- 八皇后的题目
- 八皇后的解法
- 八皇后的问题
- 八皇后的问题
- 八皇后的问题
- `## 八皇后的判断 ###
- 八皇后及N皇后的解法
- 八皇后、N皇后问题的求解。
- ZZY的新BLOG
- ZZY的爱好
- ZZY的宠物
- ZZY的宠物
- ZZY的爱好
- ZZY的困惑
- ZZY的宠物
- ZZY的宠物
- 八皇后问题的实现
- lucene学习笔记(三)lucene搜索查询
- 算法之路三:HUD OJ:2007
- 从零实现一个最精简的select网络服务模型
- 第十五章 Android性能优化
- Java环境变量设置解析
- ZZY的八皇后
- 使用Springboot快速搭建项目
- 《Android 开发艺术探索》读书笔记
- c++程序性能的初步优化与分析
- Cgroup文件系统
- 神经网络深入(连载6)物种形成
- [Leetcode] 68. Text Justification 解题报告
- javascript 布尔对象
- 跬步系列 - word2vector