本文已被:浏览 1436次 下载 2433次
Received:April 03, 2013 Revised:May 13, 2013
Received:April 03, 2013 Revised:May 13, 2013
中文摘要: 迄今为止, 已有多种基于不同理论的八皇后问题算法. 本文提出一种类似筛法的新算法: 在棋盘某一格放上一个皇后的同时划去经过这一格的纵、横、及正负45度线上的所有格位, 或者说筛去这些格位;后来的皇后只能放在未被占据或划去的格位上;若所有的皇后都能放入一个格位, 则得到了一个布局或一个解. 依据这种思路容易制定一个N皇后问题的简洁算法. 实验结果表明, 筛法算法的效率大大高于经典的回溯法.
Abstract:So far, there have been many different algorithm of eight queens problem. A similar sieve algorithm is presented in this paper: Using a algorithm similar to the sieve method in number theory: place the first queen in the first grid of the first row, and mark out the row, the column, the downward diagonal and the upward diagonal through the first queen;then place the second queen on the most left grid of the unmarked grid of the second row, and mark out the row, the column, the downward diagonal and the upward diagonal through the second queen;like this, queens are added, one by one. if all the queens can be placed on the board, a layout or a solution received. Traversing all grids of all row, we would get all solutions of N-queens problem. Based on the simple idea, we can develop a N-queens program easily. The experimental results show that the efficiency of the sieve program is much higher than the classic backtracking program.
keywords: N queens problem sieve method backtracking
文章编号: 中图分类号: 文献标志码:
基金项目:
Author Name | Affiliation |
CHENG Yuan-Bin | School of Mathematics & Computer Science, Jianghan University, Wuhan 430056, China |
Author Name | Affiliation |
CHENG Yuan-Bin | School of Mathematics & Computer Science, Jianghan University, Wuhan 430056, China |
引用文本:
程元斌.类似筛法的N皇后问题求解算法.计算机系统应用,2013,22(10):147-150
CHENG Yuan-Bin.Sieve Algorithm to N Queens Problem.COMPUTER SYSTEMS APPLICATIONS,2013,22(10):147-150
程元斌.类似筛法的N皇后问题求解算法.计算机系统应用,2013,22(10):147-150
CHENG Yuan-Bin.Sieve Algorithm to N Queens Problem.COMPUTER SYSTEMS APPLICATIONS,2013,22(10):147-150