bahuanghou111
#include<stdio.h>
int map[8][8]={0};
int count=0;
int safe(int x,int y)
{
int i;
int j;
for(i=0;i<8;i++)
{
if(map[i][y]!=0)
return 0;
}
for(j=0;j<8;j++)
{
if(map[x][j]!=0)
return 0;
}
for(i=x,j=y;i>=0&&j>=0;i--,j--)
{
if(map[i][j]!=0)
return 0;
}
for(i=x,j=y;i>=0&&j<8;i--,j++)
{
if(map[i][j]!=0)
return 0;
}
return 1;
} void queen(int i)
{
if(i==8)
{
count++;
return;
}
for(int j=0;j<8;j++)
{
if(safe(i,j))
{
map[i][j]=1;
queen(i+1);
map[i][j]=0;
}
}
}
int main()
{
queen(0);
printf("%d",count);
return 0;
}
bahuanghou111的更多相关文章
随机推荐
- mysql sql优化实例
mysql sql优化实例 优化前: pt-query-degist分析结果: # Query 3: 0.00 QPS, 0.00x concurrency, ID 0xDC6E62FA021C85B ...
- libeventReferenceManual阅读笔记
一.01_intro.html Example:A low-level ROT13 server with Libevent 这是一个利用event实现的server实例 Example:A simp ...
- strust1与strust2,springmvc三者之间的区别?
strust1与struts2的区别 1.struts2是基于webWork的一个全新的框架,比struts1学习更方便 Struts2主要是改进了Struts1的servlet和acti ...
- ldd 命令用于判断某个可执行的binary档案含有什么动态链接库(so)
[root@NB ok]# ldd /bin/ls linux-vdso.so. => (0x00007ffd7dbf6000) libselinux.so. => /lib64/libs ...
- Sql Server 中锁的概念
锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系统 脏 ...
- Python 迭代器 & __iter__方法
转载来自: http://blog.csdn.net/bluebird_237/article/details/38894617 迭代器就是重复地做一些事情,可以简单的理解为循环,在python中实现 ...
- Maven搭建 Spring环境
http://www.cnblogs.com/huaizuo/p/4920308.html http://mvnrepository.com/artifact/commons-logging/comm ...
- C#将数据大小字节转换为MB,GB,TB
http://www.myluoluo.com/c%E5%B0%86%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%E5%AD%97%E8%8A%82%E8%BD%AC%E6 ...
- Java基础知识点2:hashCode()方法
hashCode()方法基本实现 hashCode方法是Java的Object类所定义的几个基本方法之一.我们可以深入到Object类的源码中去查看: public native int hashCo ...
- Codeforces 717G Underfail(最小费用最大流 + AC自动机)
题目 Source http://codeforces.com/problemset/problem/717/G Description You have recently fallen throug ...