• <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 閱讀(604) 評論(0)  編輯 收藏 引用

            導航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            狠狠色丁香婷婷综合久久来来去| 久久久久久久久波多野高潮| 国产精品99久久久久久人| 国产一久久香蕉国产线看观看| 国产精品久久久久久| 亚洲一区中文字幕久久| 亚洲欧洲久久av| 国产成人久久激情91| 伊人久久成人成综合网222| 无码人妻久久一区二区三区免费| 久久最近最新中文字幕大全| 欧美久久久久久午夜精品| 久久精品亚洲中文字幕无码麻豆| 久久福利片| 99久久精品午夜一区二区| 欧美激情精品久久久久久久九九九 | 久久久久亚洲精品日久生情| 久久免费精品视频| 久久午夜夜伦鲁鲁片免费无码影视| 香蕉久久av一区二区三区| 久久久精品国产亚洲成人满18免费网站 | 久久久久国色AV免费看图片| 久久不见久久见免费视频7| 日日狠狠久久偷偷色综合0| 伊人久久大香线蕉影院95| 久久亚洲AV成人无码国产| 久久综合九色综合欧美就去吻| 久久精品国产91久久麻豆自制 | 亚洲AV成人无码久久精品老人| 久久av高潮av无码av喷吹| 国产精品久久亚洲不卡动漫| 久久久无码精品亚洲日韩蜜臀浪潮 | 久久国产一片免费观看| 久久夜色tv网站| 一本大道久久a久久精品综合| 97久久天天综合色天天综合色hd | 亚洲午夜久久久久久噜噜噜| 一本久久综合亚洲鲁鲁五月天| 久久黄视频| 久久精品国产欧美日韩| 成人a毛片久久免费播放|