• <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>

            There is a will there is a way!

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              4 隨筆 :: 0 文章 :: 29 評論 :: 0 Trackbacks

            這里的迷宮是由0 1表示的 0表示墻, 1表示能通過

            這里我用了const int row=7,column=13;你當然可以改動這個參數. 運行后回把其中的一條路徑改成其它數字
            你會看到的,

            #include? < iostream >
            #include?
            < stack >
            using ? namespace ?std;
            const ? int ?row? = ? 7 ;
            const ? int ?column? = ? 13 ;
            int ?table[row][column];
            // struct?position{
            ??
            // ??int?prow;
            ????
            // int?pcolumn;
            // };
            void ?settable()
            {
            ????
            ????cout
            << " Please?input?table[ " ;
            ????cout
            << row << " ][ " ;
            ????cout
            << column;
            ????cout
            << " ](using?0?or?1):\n " ;
            ????
            for ( int ?i = 0 ;i < row;i ++ )?
            ????????
            for ( int ?j = 0 ;j < column;j ++ )
            ????????????cin
            >> table[i][j];
            ????
            // cout<<"Input?1?go?on?and?0?end:\n";
            ????
            }

            int ?solvepass(stack < int > ? & P, int ?i, int ?j)
            {
            ????
            int ?count = 0 ;
            ???
            // ?int?count1=0;
            ???? while (i != row - 1 ? || ?j != column - 1 )
            ????
            {
            ????????count
            = 0 ;
            ???????
            // ?count1=0;
            ???????? if (i - 1 >= 0 ? && ?table[i - 1 ][j] == 1 )?
            ????????
            {
            ????????????count
            = 1 ;
            ????????????table[i][j]
            = 9 ;
            ????????????P.push(i);P.push(j);?
            // ?cout<<"i="<<i<<"?j="<<j<<endl;
            ????????????i -= 1 ;? // cout<<"i="<<i<<"?j="<<j<<endl;
            ???????????? continue ;
            ????????}

            ????????
            if (i + 1 < row? && ?table[i + 1 ][j] == 1 )
            ????????
            {
            ????????????count
            = 1 ;
            ????????????table[i][j]
            = 9 ;
            ????????????P.push(i);P.push(j);
            // cout<<"i="<<i<<"?j="<<j<<endl;
            ????????????i += 1 ; // cout<<"i="<<i<<"?j="<<j<<endl;
            ????????????? continue ;
            ????????}
            ?
            ????????
            if (j - 1 >= 0 ? && ?table[i][j - 1 ] == 1 )
            ????????
            {
            ????????????count
            = 1 ;
            ????????????table[i][j]
            = 9 ;
            ????????????P.push(i);P.push(j);
            // cout<<"i="<<i<<"?j="<<j<<endl;
            ????????????j -= 1 ;? // cout<<"i="<<i<<"?j="<<j<<endl;
            ???????????? continue ;
            ????????}

            ????????
            if (j + 1 < column? && ?table[i][j + 1 ] == 1 )
            ????????
            {
            ????????????count
            = 1 ;
            ????????????table[i][j]
            = 9 ;
            ????????????P.push(i);P.push(j);
            // cout<<"i="<<i<<"?j="<<j<<endl;
            ????????????j += 1 ; // ?cout<<"i="<<i<<"?j="<<j<<endl;
            ???????????? continue ;
            ????????}

            ????????
            if (count == 0 )
            ????????
            {
            ????????????
            int ?n = P.top();
            ????????????P.pop();
            ????????????
            int ?m = P.top();
            ????????????P.pop();
            ????????????table[i][j]
            = 2 ; // cout<<"i="<<i<<"?j="<<j<<endl;
            ????????????i = m;j = n; // cout<<"i="<<i<<"?j="<<j<<endl;
            ????????}

            ???????
            // ?else?return?1;
            ???????
            // ?count1=1;
            ????}

            ?????
            ?????P.push(row
            - 1 );P.push(column - 1 )?;
            ??????table[row
            - 1 ][column - 1 ] = 9 ;
            }

            void ?outputtable()
            {
            ????
            // cout<<"Result?table?is:\n";
            ???? for ( int ?i = 0 ;i < row;i ++ )
            ????
            {
            ????????cout
            << endl;
            ????????
            for ( int ?j = 0 ;j < column;j ++ )
            ????????????cout
            << table[i][j] << " ? " ;
            ????????}

            }

            void ?outputpass(stack < int >& P)
            {
            ????stack
            < int > ?S;
            ????cout
            << " \nThe?result?pass?is:\n " ;
            ????
            while ( ! P.empty())
            ????
            {
            ????????
            int ?sp = P.top();
            ????????P.pop();?
            ????????
            int ?q = P.top();??P.pop();
            ????????S.push(q);?S.push(sp);
            ????????
            ????}

            ????
            while ( ! S.empty())
            ????
            {
            ????????
            int ?j = S.top();
            ????????S.pop();
            ????????
            int ?i = S.top();
            ????????S.pop();
            ????????cout
            << " ( " << i << " , " << j << " )?\n " ;
            ????}

            }

            int ?main()
            {
            ????
            // int?row,column;
            ????
            // int?table[row][column];
            ????stack < int > ?P; // save?the?pass?ways
            ???? int ?s;
            ????cout
            << " Input?1?go?on?and?0?end:\n " ;
            ????
            while (cin >> s)
            ????
            {
            ????????
            if ( ! s)? break ;
            ????????settable();?
            // set?table
            ????????cout << " \nThe?orenage?table?is:\n " ;
            ????????outputtable();
            ????????solvepass(P,
            0 , 0 );? // solve?this?problem
            ????????cout << " \nThe?result?table?is:\n " ;
            ????????outputtable();
            ????????outputpass(P);
            ????????cout
            << " Input?1?go?on?and?0?end:\n " ;
            ????}

            ????
            return ? 1 ;
            }

            posted on 2006-04-10 23:21 王直元 閱讀(649) 評論(0)  編輯 收藏 引用
            韩国三级大全久久网站| 91麻豆国产精品91久久久| 尹人香蕉久久99天天拍| 久久免费美女视频| 狠狠久久亚洲欧美专区| 久久99国产综合精品| 丁香狠狠色婷婷久久综合| 精品少妇人妻av无码久久| 国产精品99久久久久久人| 久久国产精品-国产精品| 777久久精品一区二区三区无码 | 成人国内精品久久久久影院| 久久免费的精品国产V∧| 无码伊人66久久大杳蕉网站谷歌 | 久久影视综合亚洲| 久久久这里只有精品加勒比| 精品熟女少妇AV免费久久| 熟妇人妻久久中文字幕| 国产精品99久久99久久久| 91精品观看91久久久久久| 久久国产影院| 久久久久久久久久久精品尤物| 亚洲AV无码久久精品蜜桃| 久久精品国产久精国产| 久久精品国产精品亚洲人人| 久久99久久99精品免视看动漫 | 国内精品伊人久久久久| 久久久久亚洲AV成人网| 久久天天躁夜夜躁狠狠躁2022| 成人久久精品一区二区三区| 久久国产V一级毛多内射| 亚洲精品乱码久久久久久| yellow中文字幕久久网| 一本色道久久99一综合| 久久国产精品波多野结衣AV | 欧美麻豆久久久久久中文| 无码专区久久综合久中文字幕 | 99久久精品国产综合一区| 亚洲国产欧美国产综合久久| 国产成人久久精品二区三区| 色8久久人人97超碰香蕉987|