当前位置:网站首页>Solution of Queen n problem
Solution of Queen n problem
2022-07-02 15:14:00 【MASJLE】
#include <stdio.h>
#include <malloc.h>
#include <math.h>
int place(int* paraSolution, int paraT){
int j;
for (j = 1; j < paraT; j ++){
if ((abs(paraT - j) == abs(paraSolution[j] - paraSolution[paraT])) || (paraSolution[j] == paraSolution[paraT]))
return 0;
}
return 1;
}
void backtracking(int* paraSolution, int paraN, int paraT){
int i;
if (paraT > paraN){
for (i = 1; i <= paraN; i ++)
printf("%d ", paraSolution[i]);
printf("\r\n");
}else{
for (i = 1; i <= paraN; i ++){
paraSolution[paraT] = i;
if (place(paraSolution, paraT))
backtracking(paraSolution, paraN, paraT + 1);
}
}
}
void nQueen(int paraN){
int i;
int* solution = (int*)malloc((paraN + 1) * sizeof(int));
for (i = 0; i <= paraN; i ++)
solution[i] = 0;
backtracking(solution, paraN, 1);
}
int main(){
printf(" Enter the number of queens :\r\n");
int n;
scanf("%d",&n);
nQueen(n);
return 0;
}

边栏推荐
- .NET Core 日志系统
- Topology architecture of the minimum deployment of tidb cluster
- LeetCode 2320. Count the number of ways to place the house
- Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
- How does CTO help the business?
- qml 弹窗框架,可定制
- Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
- [noi Simulation Competition] scraping (dynamic planning)
- php获取数组中键值最大数组项的索引值的方法
- TiDB 软件和硬件环境建议配置
猜你喜欢

03_线性表_链表

19_Redis_宕机后手动配置主机

Base64 coding can be understood this way
![[noi Simulation Competition] scraping (dynamic planning)](/img/ee/27a07f80207a2925f5065e633eb39f.png)
[noi Simulation Competition] scraping (dynamic planning)

03_線性錶_鏈錶

21_ Redis_ Analysis of redis cache penetration and avalanche

Why can't programmers who can only program become excellent developers?

LeetCode 209. 长度最小的子数组

btrace-(字节码)动态跟踪工具

MFC timer usage
随机推荐
C语言习题---(数组)
MFC 控制台打印,弹出对话框
学习使用php将时间戳转换为大写日期的方法代码示例
19_Redis_宕机后手动配置主机
2021-2022学年编译原理考试重点[华侨大学]
MFC 定时器使用
13_Redis_事务
forEach的错误用法,你都学废了吗
Tidb data migration tool overview
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
21_Redis_浅析Redis缓存穿透和雪崩
原则、语言、编译、解释
C language exercises - (array)
LeetCode 2310. 个位数字为 K 的整数之和
实用调试技巧
Btrace- (bytecode) dynamic tracking tool
【题解】Educational Codeforces Round 82
Record an error report, solve the experience, rely on repetition
php获取数组中键值最大数组项的索引值的方法
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting