Another implementation of the Eight Queens algorithm (C # version)

Source: Internet
Author: User

Eight queens:

The eight Queens question, an old and famous problem, is a typical case of backtracking algorithms. The problem is the international chess player Max Bessel in 1848: Put eight queens on the 8x8 chess, so that they can not attack each other, that is, any two queens can not be in the same row, the same column or the same slash, ask how many kinds of pendulum. Gauss thinks there are 76 kinds of schemes. In 1854, in the Chess magazine in Berlin, different authors published 40 different solutions, and later some of them solved 92 kinds of results using the method of graph theory. After the invention of computer, there are many computer languages to solve this problem.

Icon:

  

My solution:

There are a lot of methods on the Internet, most of the abstraction is difficult to understand, and the great God has sorted out the version of 10 lines of code, a time of shock for heaven and the people were startled. How to write eight queens in C + + in 10 rows? You can close this article if you understand the force of the great Gods of each road.

  

Now give my personal version, the algorithm process description of the more detailed, and added a lot of comments, especially the process control of the annotations more, easy to understand. The core of the algorithm is based on the location of the unknown location calculation. This implementation is not the most efficient way, but it is very helpful for those who have just contacted this algorithm, and have not collated their ideas.

Results

  

  

The source code is as follows : Eight Queens

Another implementation of the Eight Queens algorithm (C # version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.