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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            HDOJ 1253 HDU 1253 勝利大逃亡 ACM 1253 IN HDU

            Posted on 2010-08-25 11:30 MiYu 閱讀(684) 評論(0)  編輯 收藏 引用 所屬分類: ACM ( 搜索 )

            MiYu原創(chuàng), 轉(zhuǎn)帖請注明 : 轉(zhuǎn)載自 ______________白白の屋    

             

             題目地址:

                  http://acm.hdu.edu.cn/showproblem.php?pid=1253 

            題目描述:

            勝利大逃亡

            Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
            Total Submission(s): 4785    Accepted Submission(s): 1454


            Problem Description
            Ignatius被魔王抓走了,有一天魔王出差去了,這可是Ignatius逃亡的好機(jī)會.

            魔王住在一個(gè)城堡里,城堡是一個(gè)A*B*C的立方體,可以被表示成A個(gè)B*C的矩陣,剛開始Ignatius被關(guān)在(0,0,0)的位置,離開城堡的門在(A-1,B-1,C-1)的位置,現(xiàn)在知道魔王將在T分鐘后回到城堡,Ignatius每分鐘能從一個(gè)坐標(biāo)走到相鄰的六個(gè)坐標(biāo)中的其中一個(gè).現(xiàn)在給你城堡的地圖,請你計(jì)算出Ignatius能否在魔王回來前離開城堡(只要走到出口就算離開城堡,如果走到出口的時(shí)候魔王剛好回來也算逃亡成功),如果可以請輸出需要多少分鐘才能離開,如果不能則輸出-1.


             

            Input
            輸入數(shù)據(jù)的第一行是一個(gè)正整數(shù)K,表明測試數(shù)據(jù)的數(shù)量.每組測試數(shù)據(jù)的第一行是四個(gè)正整數(shù)A,B,C和T(1<=A,B,C<=50,1<=T<=1000),它們分別代表城堡的大小和魔王回來的時(shí)間.然后是A塊輸入數(shù)據(jù)(先是第0塊,然后是第1塊,第2塊......),每塊輸入數(shù)據(jù)有B行,每行有C個(gè)正整數(shù),代表迷宮的布局,其中0代表路,1代表墻.(如果對輸入描述不清楚,可以參考Sample Input中的迷宮描述,它表示的就是上圖中的迷宮)

            特別注意:本題的測試數(shù)據(jù)非常大,請使用scanf輸入,我不能保證使用cin能不超時(shí).在本OJ上請使用Visual C++提交.
             

            Output
            對于每組測試數(shù)據(jù),如果Ignatius能夠在魔王回來前離開城堡,那么請輸出他最少需要多少分鐘,否則輸出-1.
             

            Sample Input
            1 3 3 4 20 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0
             

            Sample Output
            11
             

             

             題目分析:

                題目是很簡單的一道BFS, 但是這破題竟然糾結(jié)了我一整天, 晚上11點(diǎn)的時(shí)候才A掉,YM.  
            這題和 二維矩陣的不同點(diǎn)就是有6個(gè)方向, 前后左右上下.  然后一直BFS就可以了,不需要剪枝都能過...........


            代碼如下:

             /*

            MiYu原創(chuàng), 轉(zhuǎn)帖請注明 : 轉(zhuǎn)載自 ______________白白の屋

                      http://www.cnblog.com/MiYu

            Author By : MiYu

            Test      : 1

            Program   : HDU1253

            */


            #include <iostream>

            #include <queue>

            using namespace std;

            int TLE[56][56][56];

            const int d[6][3] = { { 0,0,1 },{ 0,0,-1 },{ 0,-1,0 },{ 0,1,0 },{ 1,0,0 },{ -1,0,0 } };

            int A, B, C, T, m;

            typedef struct pos{

                   pos(){ x=y=z=n=0; } 

                   void setPos ( int a,int b,int c, int count ){ x=a;y=b;z=c;n=count; }

                   bool isEnd () { if ( x==1&&y==1&&z==1 )return true;return false; }

                   int x,y,z;  

                   int n;

            }pos;

            pos t,p;

            #define CMP(A,B) (A.n < B.n)

            typedef class Heap {

            public:

                    pos h[70000 * 2];

                    int n, p, c;

                    Heap() {

                            n = 0;

                    }

                    void inline push(pos e) {

                            for (p = ++n; p > 1 && CMP(e,h[p>>1]); h[p] = h[p>>1], p >>= 1)

                                    ;

                            h[p] = e;

                    }

                    int inline pop(pos &e) {

                            if (!n)

                                    return 0;

                            for (e = h[p = 1], c = 2; c < n

                                            && CMP(h[c += (CMP(h[c + 1],h[c]) && c < n - 1)], h[n]);

                                            h[p] = h[c], p = c, c <<= 1)

                                    ;

                            h[p] = h[n--];

                            return 1;

                    }

            }Heap;

            Heap WA;

            int RE ()

            {

                if ( A+B+C-2 > T || TLE[A][B][C] == 0 )

                     return -1;

                t.setPos ( A,B,C,0 );

                TLE[A][B][C] = 0;

                WA.push ( t );

                while ( WA.pop(t) ){ 

                       if ( t.x+t.y+t.z-2 > T-t.n )

                            continue;            

                       if ( t.isEnd() )

                            return t.n;  

                       for ( int i = 0; i != 6; ++ i ){

                             int x = t.x+d[i][0], y=t.y+d[i][1], z=t.z+d[i][2];

                             if ( TLE[ x ][ y ][ z ] != 0 ){

                                  TLE[ x ][ y ][ z ] = 0;

                                  p.setPos ( x, y, z, t.n+1 ); 

                                  if ( p.isEnd() && p.n <= T )

                                       return p.n;  

                                  if ( p.n <= T )    

                                       WA.push ( p );

                             }

                       }  

                }

                return -1;

            }

            inline bool scan_d(int &num) 

            {

                    char in;bool IsN=false;

                    in=getchar();

                    if(in==EOF) return false;

                    while(in!='-'&&(in<'0'||in>'9')) in=getchar();

                    if(in=='-'){ IsN=true;num=0;}

                    else num=in-'0';

                    while(in=getchar(),in>='0'&&in<='9'){

                            num*=10,num+=in-'0';

                    }

                    if(IsN) num=-num;

                    return true;

            }

            int main ()

            {

                int K;

                scan_d(K);

                while ( K -- ){

                       while ( WA.pop(p) ) ;

                       memset ( TLE, 0 , sizeof ( TLE ) );

                       scan_d(A); scan_d(B); scan_d(C); scan_d(T);

                       for ( int i = 1; i <= A; ++ i ){

                             for ( int j = 1; j <= B; ++ j ){

                                   for ( int k = 1; k <= C; ++ k ){

                                         scan_d(m);

                                         TLE[i][j][k] = m == 1 ? 0 : 1; 

                                   } 

                             } 

                       } 

                       TLE[1][1][1] = 1;

                       cout << RE () << endl;

                } 

                //system( "pause" );

                return 0;

            }


             

             

            国产精品日韩深夜福利久久| 亚洲精品乱码久久久久66| 久久av免费天堂小草播放| 亚洲午夜久久久| 久久人人爽人人爽人人片av高请| 久久99国产精品99久久| 久久久久久国产a免费观看黄色大片 | 麻豆精品久久久久久久99蜜桃| 久久人人爽人人爽人人av东京热| 精品久久久久久| 日本欧美久久久久免费播放网| 久久人人超碰精品CAOPOREN| 色欲久久久天天天综合网| 91久久精品视频| 国产精品无码久久久久久| 国产精品久久新婚兰兰| 国产三级精品久久| 日本免费久久久久久久网站| 伊人久久大香线焦AV综合影院| 久久精品亚洲男人的天堂| 国产福利电影一区二区三区,免费久久久久久久精 | 2021最新久久久视精品爱| 激情久久久久久久久久| 国产精品久久久久国产A级| 国产69精品久久久久久人妻精品| 久久国产精品视频| 精品视频久久久久| 国产99久久久国产精免费| 青青草原1769久久免费播放| 国产精品视频久久| 久久99精品久久久久久久久久| 中文字幕乱码久久午夜| 伊人久久大香线蕉综合影院首页| 亚洲精品午夜国产va久久| 深夜久久AAAAA级毛片免费看| 亚洲欧美成人久久综合中文网 | 一本久久a久久精品vr综合| 色综合久久中文字幕无码| 精品国产一区二区三区久久久狼| 久久永久免费人妻精品下载| 久久中文娱乐网|