poj 2698
来源:互联网 发布:淘宝手机充值漏洞 编辑:程序博客网 时间:2024/05/16 19:07
八皇后问题
原题大意就是棋盘上有八个皇后,但是这八个不能再一直线出现,求各个皇后能够个不伤害的排法
#include<stdio.h>#include<math.h>#define max 8int sum=0,queen[max];void print(){ int i,j; printf("NO:%d\n",++sum); for(i=0;i<max;i++) { for(j=0;j<max;j++) { if(j!=queen[i]) printf("0 "); else printf("1"); } } }int place(int n){ int i; for(i=0;i<max;i++) { if(queen[i]==queen[n]||abs(queen[i]-queen[n])==abs(i-n)) return 1; } return 0;}void queens(int n){ int i; for(i=0;i<max;i++) { queen[n]=i; if(n==max-1) print(); else queens(n+1); } } int main() { queens(0); system("pause"); return 0; }各位,近几天将要考试,解题报告可能比较粗糙,请各位见谅。
0 0
- poj 2698
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- mac系统升级到了10.10.但是eclipse中运行不识别真机了
- 把程序集安装到全局程序集缓存中的步骤
- [leetcode]String to Integer (atoi)
- To find sum of two numbers without using any operator. Only use of printf() is allowed.
- Android:给图片加边框
- poj 2698
- JFreeChart 项目实例
- Android:图形图像之使用Canvas,Paint绘图
- SQL到NOSQL的思维转变
- java 内存模型
- 硬盘数据恢复与编程
- 10、黑马程序员-OC语言@property @synthesize和id
- Linux IP代理筛选系统
- [leetcode]ZigZag Conversion