• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            八皇后的簡單解法

            #include <iostream.h>
            #include<io.h>
            const int QUENS = 7;
            int getcol(int q[],int n,const int firstCol)
            {//q表示每個皇后的列位置,firstCol是搜索列位置時的起始位置
            //n表示正在搜索第n個皇后的列位置,皇后的名稱從0--n編號,也是皇后的行號
             bool b = true;
             int i = firstCol;
             for (i = firstCol; i<=QUENS ; i++) {
              for (int j=0; j<n; j++) {
               if(q[j] == i || (n+q[j]==i+j)||(n+i == j+q[j])){
                b = false;
                break;
               }
              }
              if(j == n)
                return i;
              else if(firstCol > QUENS) return firstCol;
             }
             if(!b) return QUENS+1;
            }
            void EQ(int q[],int n){
             void disp(int[]);
             int col = QUENS+1;
             bool b = true;
             int firstCol = 0;
             while (QUENS >= (col=getcol(q,n,firstCol))){
              if(QUENS == n){
               q[n] = col;
               disp(q);
               return ;
              }
              else{
               q[n] = col;
               firstCol = col +1;
               EQ(q,n+1);
              }
             }
             
            }
            void disp(int q[])
            {//顯示一種排列
             static count = 0;
             count++;
             cout<<"number "<<count<<" : ";
             for (int i=0; i<=QUENS; i++)
              cout<<q[i]+1<<" ";
             cout<<endl;
            }
            void outTofile()
            {//由于結果比較多,所以把結果重定向輸出到文件里頭了,文件名是EightQuen.txt
             int old = _dup(1);
             FILE* pf;
             pf = fopen("EightQuen.txt","w");
             if(!pf)  throw 0;
             _dup2((fileno(pf)),_fileno(stdout));
             int q[8];
             EQ(q,0);
            fclose(pf);
             _dup2(old,_fileno(stdout));

            }
            void main()
            {
            outTofile();
            }

            posted on 2007-09-14 14:41 zlf 閱讀(609) 評論(0)  編輯 收藏 引用

            導航

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久人人爽人人爽人人片AV麻烦 | A级毛片无码久久精品免费| 亚洲国产一成人久久精品| 亚洲日本va中文字幕久久| 欧美激情精品久久久久| 欧美久久久久久| 狠狠狠色丁香婷婷综合久久五月 | 久久人人爽人人爽人人av东京热| 久久精品国产亚洲AV香蕉| 九九99精品久久久久久| 久久香综合精品久久伊人| 99久久综合狠狠综合久久止| 色婷婷久久久SWAG精品| 久久国产成人精品麻豆| 久久午夜夜伦鲁鲁片免费无码影视| 日本一区精品久久久久影院| 亚洲国产精品一区二区三区久久| 国产午夜久久影院| 天天躁日日躁狠狠久久| 亚洲精品国产自在久久| 狠狠综合久久综合中文88| 国产午夜久久影院| 国产精品99久久99久久久| 久久无码中文字幕东京热| 久久亚洲天堂| 久久国产视屏| 一本大道加勒比久久综合| 国产精品一区二区久久| 久久99国产精品尤物| 天天爽天天狠久久久综合麻豆| 性高朝久久久久久久久久| 久久涩综合| 国产精品美女久久福利网站| 亚洲v国产v天堂a无码久久| 精品欧美一区二区三区久久久| 国产V综合V亚洲欧美久久| 久久A级毛片免费观看| 77777亚洲午夜久久多喷| 成人综合伊人五月婷久久| 2021少妇久久久久久久久久| 国产一区二区三区久久精品|