• <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年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(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逃亡的好機會.

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


             

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

            特別注意:本題的測試數(shù)據(jù)非常大,請使用scanf輸入,我不能保證使用cin能不超時.在本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點的時候才A掉,YM.  
            這題和 二維矩陣的不同點就是有6個方向, 前后左右上下.  然后一直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;

            }


             

             

            久久这里只精品99re66| 久久中文骚妇内射| 久久精品二区| 亚洲精品第一综合99久久 | 精品综合久久久久久97超人| 久久91精品国产91久久小草 | 亚洲国产精品久久久久网站| 国产精品青草久久久久福利99 | 久久久久亚洲AV成人片| 久久精品国内一区二区三区| 一本久久精品一区二区| 久久综合综合久久97色| 久久受www免费人成_看片中文| 久久精品毛片免费观看| 四虎国产精品成人免费久久| 99麻豆久久久国产精品免费| 久久精品国产久精国产一老狼| 国产精品久久毛片完整版| 超级碰碰碰碰97久久久久| 99久久综合国产精品二区| 久久男人Av资源网站无码软件| 久久乐国产精品亚洲综合| 国内精品久久九九国产精品| 2020久久精品亚洲热综合一本| 国产一区二区精品久久凹凸| 国产91色综合久久免费| 一97日本道伊人久久综合影院| 国产99久久久国产精免费| 久久ww精品w免费人成| 久久国产精品77777| 国内精品伊人久久久久| 国产精品久久久久9999| 2022年国产精品久久久久| 久久无码人妻一区二区三区| 中文字幕人妻色偷偷久久| 久久久久人妻一区二区三区| 国产色综合久久无码有码| 久久久久av无码免费网| 亚洲国产另类久久久精品| 一本色综合网久久| 久久精品国产亚洲av麻豆色欲|