Colin's Blog

Recent content on Colin's Blog

马上订阅 Colin's Blog RSS 更新: https://blog.oyyko.com/index.xml

N queens Problem

finalwind42@gmail.com (Oyyko)
2020年12月27日 08:00

This article will provide a fast way to find a solution for the famous N queens problem.

Note: we only try to find one possibility of all positions of chesses, NOT (ALL posibilities).

For example, when N=8, there are 92 ways to put the chesses. However, our algorithm just focus on finding one of these 92 ways.

If you still feels not familar with the problem we will solve. Please Google 8 queens problem and look down.

N=4

When N=4, there are only two ways to put these chesses.

10100200013100040010
10010210003000140100

Our program, as I just said, will try to find one of the two ways.

So, Here we go~

Code

  1#include <stdio.h>  2#include <stdlib.h>  3#include <time.h>  4#include <string.h>  5  6#define N 123456789  7  8  9//...

剩余内容已隐藏

查看完整文章以阅读更多