当前位置:编程学习 > VC++ >>

基于VC++2012图形化解决皇后问题

[cpp]    

八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题。该问题是十九世纪著名的数学家高斯1850年提出:在8X8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问有多少种摆法。 高斯认为有76种方案。1854年在柏林的象棋杂志上不同的作者发表了40种不同的解,后来有人用图论的方法解出92种结果。计算机发明后,有多种方法可以解决此问题。
我们用图形来解决之、
看效果

 

\

\

\

 

\

 

 
[cpp] 
#pragma once 
#include<math.h> 
 
 
namespace Queen { 
 
    using namespace System; 
    using namespace System::ComponentModel; 
    using namespace System::Collections; 
    using namespace System::Windows::Forms; 
    using namespace System::Data; 
    using namespace System::Drawing; 
 
    /// <summary> 
    /// Form1 摘要 
    /// 
    /// 警告: 如果更改此类的名称,则需要更改 
    ///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
    ///          “资源文件名”属性。否则, 
    ///          设计器将不能与此窗体的关联 
    ///          本地化资源正确交互。 
    /// </summary> 
    public ref class Form1 : public System::Windows::Forms::Form 
    { 
    public: 
        Form1(void) 
        { 
            InitializeComponent(); 
            // 
            //TODO: 在此处添加构造函数代码 
            // 
        } 
 
    protected: 
        /// <summary> 
        /// 清理所有正在使用的资源。 
        /// </summary> 
        ~Form1() 
        { 
            if (components) 
            { 
                delete components; 
            } 
        } 
    private: System::Windows::Forms::ComboBox^  comboBox1; 
    private: System::Windows::Forms::TextBox^  textBox1; 
    private: System::Windows::Forms::Button^  button1; 
    private: System::Windows::Forms::Label^  label1; 
    private: System::Windows::Forms::Label^  label2; 
 
    private: 
        /// <summary> 
        /// 必需的设计器变量。 
        /// </summary> 
        System::ComponentModel::Container ^components; 
 
#pragma region Windows Form Designer generated code 
        /// <summary> 
        /// 设计器支持所需的方法 - 不要 
        /// 使用代码编辑器修改此方法的内容。 
        /// </summary> 
        void InitializeComponent(void) 
        { 
            this->comboBox1 = (gcnew System::Windows::Forms::ComboBox()); 
            this->textBox1 = (gcnew System::Windows::Forms::TextBox()); 
            this->button1 = (gcnew System::Windows::Forms::Button()); 
            this->label1 = (gcnew System::Windows::Forms::Label()); 
            this->label2 = (gcnew System::Windows::Forms::Label()); 
            this->SuspendLayout(); 
            //  
            // comboBox1 
            //  
            this->comboBox1->FormattingEnabled = true; 
            this->comboBox1->Location = System::Drawing::Point(134, 602); 
            this->comboBox1->Name = L"comboBox1"; 
            this->comboBox1->Size = System::Drawing::Size(121, 20); 
            this->comboBox1->TabIndex = 0; 
            this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged); 
         

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,