惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
D
Docker
云风的 BLOG
云风的 BLOG
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
GbyAI
GbyAI
T
Tailwind CSS Blog
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
C
Check Point Blog
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
N
Netflix TechBlog - Medium
B
Blog RSS Feed
腾讯CDC
aimingoo的专栏
aimingoo的专栏

博客园 - 程序猿101

2024年总结。。。。2025年规划。 对分布式一些理解 观察者模式 用redis实现悲观锁(后端语言以php为例) 只用200行Go代码写一个自己的区块链!(转) 用户中心 - 博客园 php的生命周期的概述 linux网络编程1 最简单的socket编程 mysql 慢查询 2016年终总结。。。六年从创业到技术的历程 Linux下chkconfig命令详解 这个简单明了啊 JS的prototype和__proto__ Constructor vagrant homestead laravel 编程环境搭建 发现一个百度的密码。。。记最近一段时间的php感想 mysql 的简单优化 百度面试题 字符串相似度 算法 similar_text 和页面相似度算法 百度的面试题 合并两个有序的数组 PHP性能优化工具–xhprof安装 Ecshop :后台添加新功能 菜单及 管理权限 配置
八皇后问题c语言版(xcode下通过)
程序猿101 · 2020-02-26 · via 博客园 - 程序猿101
 1 int arr[8][8] = {0}; //arr[row][col];
 2 
 3 
 4 //表示第几个棋子
 5 int check(int row,int col){
 6   
 7     //1,同一列不能有皇后
 8     for(int i = 0; i < 8; i++){
 9         if(arr[i][col] == 1){
10             return 0;
11         }
12     }
13     
14     //2,左斜上方,不能有皇后。
15     for(int i = row, j = col; i >= 0 && j >= 0; i--,j--){
16         if(arr[i][j] == 1){
17             return 0;
18         }
19     }
20     
21     //3,右上方,不能有皇后
22     for(int i = row, j = col; i >= 0 && j < 8; i--,j++){
23         if(arr[i][j] == 1){
24             return 0;
25         }
26     }
27     
28     return 1;
29 }
30 
31 void printfArr(){
32     for(int list = 0; list < 8; list++){
33         for(int line = 0; line < 8; line++){
34             if(arr[list][line] == 1){
35                 printf("(%d,%d)",list,line);
36             }
37         }
38     }
39     printf("\n");
40 }
41 
42 int count = 0;
43 void eightQueue(int row){
44     
45     if(row > 7){
46         printfArr();
47         count++;
48         return ;
49     }
50     
51     for(int col = 0; col < 8; col++){
52         if(check(row,col) == 1){
53             arr[row][col] = 1;
54             eightQueue(row + 1);
55             arr[row][col] = 0;
56         }
57     }
58 }