日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/6/17 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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 DescriptionIgnatius被魔王抓走了,有一天魔王出差去了,這可是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 Input1 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 Output11

?

?題目分析:

?? ?題目是很簡單的一道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;

}


?

?

轉(zhuǎn)載于:https://www.cnblogs.com/MiYu/archive/2010/08/20/1804162.html

總結(jié)

以上是生活随笔為你收集整理的HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。