HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
题目地址:
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
魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ignatius能否在魔王回来前离开城堡(只要走到出口就算离开城堡,如果走到出口的时候魔王刚好回来也算逃亡成功),如果可以请输出需要多少分钟才能离开,如果不能则输出-1.
特别注意:本题的测试数据非常大,请使用scanf输入,我不能保证使用cin能不超时.在本OJ上请使用Visual C++提交.
题目分析:
这题和 二维矩阵的不同点就是有6个方向, 前后左右上下. 然后一直BFS就可以了,不需要剪枝都能过...........
代码如下:
/*
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
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;
}
转载于:https://www.cnblogs.com/MiYu/archive/2010/08/20/1804162.html
HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU相关推荐
- HDU 1429 胜利大逃亡(续) (BFS+位压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 1429 胜利大逃亡(续) bfs+状态压缩
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1429 胜利大逃亡(续)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU - 1429 胜利大逃亡(续) (BFS+状压)
题目链接 思路 因为新拿到一把钥匙所以相同位置可以重复走,一共10把钥匙二进制表示拿到的钥匙,判断下个位置是否可以走. #include <bits/stdc++.h> const int ...
- hdu 1429 胜利大逃亡(续)
状态压缩+宽搜 #include<cstdio> #include<iostream> #include<cstring> #include<queue> ...
- HDU-1253 胜利大逃亡 (BFS)
好吧,上次刚傻完这次又傻了一次,先粘题目吧. 题目:HDU-1253 胜利大逃亡 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目: 胜利大 ...
- [ACM] hdu 1253 胜利大逃亡 (三维BFS)
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...
- HDU 1253 胜利大逃亡
胜利大逃亡 Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 1253 ...
- HDU 1253 - 胜利大逃亡
HDU 1253 - 胜利大逃亡 Problem: a* b* c 立方体,从(1,1,1)到(a,b,c),最短路<=限制时间 Solution: BFS Code: #include< ...
最新文章
- SAP MM PR单据中采购组为空带来的问题
- mysql 分组占比_含泪整理MySQL索引
- 二维数组||考试成绩统计: 案例描述:有三名同学(张三,李四,王五),在一次考试中的成绩分别如下表,请分别输出三名同学的总成绩
- boost::mp11::mp_push_back相关用法的测试程序
- JS实现省市联动效果
- oracle having用法
- linux查进程内存问题,关于linux下内存问题排查的工具
- php 启动管理工具下载,PHP管理工具compser windows下安装
- 区别js中的3/2(结果1.5))与 java 中的 2/3(结果:0)
- Bailian2972 确定进制(POJ NOI0113-34,POJ NOI0201-1973)【暴力+进制】
- mysql canal 安装测试_canal安装配置与mysql操作监听,我已经帮你踩过了所有的坑...
- 使用HttpClient下载网络图片
- 199的Eagle一点都不香了!这款Billfish,让你不花钱免费“嫖”
- 0517 libdroid MyDriver2-397 easy_go攻防世界
- 组策略设置计算机计划任务,组策略 运行计划任务 Powershell
- linux系统pcre是什么作用,Linux下安装PCRE
- 解决Android调试微信页面,chrome的inspect弹出空白
- 2022危险化学品经营单位主要负责人考试题库及答案
- PHP实现生成推广海报
- linux fuser主机关闭,linux 下强制umount+Fuser命令详解
热门文章
- 交叉编译arm-none-linux-gnueabi-gcc: No such file or directory
- windows下vim高亮systemverilog
- php获取ios或android通过文件头(header)传过来的坐标,通过百度接口获取具体城市和地址,并存入到session中...
- echarts 表格与 div 之间 空白的设置
- 在eclipse中使用Lombok
- RxJava的初步认识
- .net IL 指令速查
- FirstApp,iphone开发学习总结7,相机
- Oracle 日志文件
- hdu5007 小水题