• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              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 王直元 閱讀(648) 評論(0)  編輯 收藏 引用
            久久国产劲爆AV内射—百度| 91久久精品国产成人久久| 麻豆精品久久精品色综合| 日产精品99久久久久久| 区久久AAA片69亚洲| 久久夜色精品国产亚洲| 久久人人爽人人爽人人片AV东京热| 久久久久无码国产精品不卡| 久久久久国产精品麻豆AR影院 | 久久不见久久见免费视频7| 久久精品aⅴ无码中文字字幕不卡| 亚洲精品无码专区久久同性男 | 国内精品久久久久影院老司| 无码八A片人妻少妇久久| 精品人妻伦九区久久AAA片69| 久久人妻少妇嫩草AV蜜桃| 亚洲综合伊人久久综合| 国产精品久久久久久福利漫画| 国产精品久久99| 久久久久亚洲精品男人的天堂| 日韩十八禁一区二区久久| 一本久久a久久精品综合香蕉| 久久精品一区二区三区AV| 久久99精品久久久久久动态图| 久久电影网一区| 无码8090精品久久一区 | 亚洲日本久久久午夜精品| 婷婷久久久亚洲欧洲日产国码AV| 久久影院综合精品| 久久996热精品xxxx| 久久久久久久久久久久久久| 国产精品久久国产精麻豆99网站| 精品欧美一区二区三区久久久| 久久亚洲精品国产亚洲老地址| 久久久久99精品成人片试看 | 婷婷久久综合| 国产亚洲婷婷香蕉久久精品| 色偷偷91久久综合噜噜噜噜| 91精品国产乱码久久久久久| 久久中文字幕无码专区| 久久久中文字幕|