• <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 閱讀(680) 評論(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ī)會.

            魔王住在一個城堡里,城堡是一個A*B*C的立方體,可以被表示成A個B*C的矩陣,剛開始Ignatius被關(guān)在(0,0,0)的位置,離開城堡的門在(A-1,B-1,C-1)的位置,現(xiàn)在知道魔王將在T分鐘后回到城堡,Ignatius每分鐘能從一個坐標(biāo)走到相鄰的六個坐標(biāo)中的其中一個.現(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;

            }


             

             

            久久久久亚洲av无码专区| 精品精品国产自在久久高清| 久久精品中文字幕一区| 久久激情五月丁香伊人| 欧美精品乱码99久久蜜桃| 综合网日日天干夜夜久久| 久久精品亚洲中文字幕无码麻豆 | 欧美久久一级内射wwwwww.| 亚洲美日韩Av中文字幕无码久久久妻妇| 亚洲v国产v天堂a无码久久| 国产亚洲色婷婷久久99精品| 精品无码久久久久久久久久| 精品人妻伦九区久久AAA片69| 亚洲综合精品香蕉久久网97| 亚洲国产成人久久综合区| 欧美综合天天夜夜久久| 精品国产99久久久久久麻豆| 久久se精品一区精品二区国产| 一本一本久久A久久综合精品| 久久精品一区二区三区中文字幕 | 精品久久久久久无码国产| 日韩av无码久久精品免费| 色播久久人人爽人人爽人人片aV| 久久精品国产亚洲AV无码娇色 | 久久人人爽人人爽人人片AV东京热| 久久精品中文字幕无码绿巨人| 天堂无码久久综合东京热| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 国产成人久久精品二区三区| 日韩精品久久无码中文字幕| 久久久久亚洲AV成人网人人网站| 久久亚洲精品中文字幕三区| 囯产极品美女高潮无套久久久| 亚洲乱码日产精品a级毛片久久| 久久久无码精品午夜| 国产精品欧美久久久久无广告 | 久久亚洲2019中文字幕| 国产精品美女久久久网AV| 久久99精品国产麻豆蜜芽| 亚洲伊人久久大香线蕉苏妲己| 色综合久久久久网|