• <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)  編輯 收藏 引用
            99久久免费只有精品国产| 久久乐国产综合亚洲精品| 7国产欧美日韩综合天堂中文久久久久| 99久久无码一区人妻a黑| 久久久久久A亚洲欧洲AV冫| 久久这里只有精品首页| 久久91精品久久91综合| 97精品依人久久久大香线蕉97 | 久久99热只有频精品8| 国内精品久久久久国产盗摄| 色婷婷综合久久久中文字幕| 国产精品九九久久免费视频 | 国产亚洲精午夜久久久久久| 国内高清久久久久久| 久久精品国产福利国产琪琪| 国产精品国色综合久久| 久久久久高潮综合影院| 久久久久国色AV免费看图片| 国产精品久久久久天天影视| 精品综合久久久久久98| 久久AⅤ人妻少妇嫩草影院| 国产精品久久久久久| 亚洲伊人久久精品影院| 日本国产精品久久| 国产精品伊人久久伊人电影| 丰满少妇人妻久久久久久| 久久久久久精品免费看SSS| 日本亚洲色大成网站WWW久久 | 久久无码人妻一区二区三区午夜| 久久久久亚洲精品中文字幕| 久久综合中文字幕| 色综合久久中文综合网| 国产精品9999久久久久| 国内精品久久久久久久97牛牛| 日日噜噜夜夜狠狠久久丁香五月 | 亚洲日本va中文字幕久久| 国内精品久久久久影院老司 | 国产成人精品免费久久久久| 欧美噜噜久久久XXX| 久久夜色精品国产噜噜噜亚洲AV| 无码AV波多野结衣久久|