hdoj1253
#include <iostream>
#include <sstream>
#include <string.h>
#include <math.h>
#include<stdlib.h>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
int A,B,C,t;
int dxy[7][3]=
{
0,-1,0,
0,1,0,
1,0,0,
-1,0,0,
0,0,1,
0,0,-1
};
int a[55][55][55];
int flag[55][55][55];
{
int x,y,z;
int step;
} now,ne;
{
int i;
memset(flag,0,sizeof(flag));
while(!q.empty())
q.pop();
now.x=0;
now.y=0;
now.z=0;
now.step=0;
flag[0][0][0]=1;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
if(now.step+1>t)
break;
for(i=0; i<6; i++)
{
int dx=now.x+dxy[i][0];
int dy=now.y+dxy[i][1];
int dz=now.z+dxy[i][2];
if(dx==A-1&&dy==B-1&&dz==C-1&&now.step+1<=t)
{
printf("%d\n",now.step+1);
return;
}
if(dx<0||dy<0||dz<0||dz>=C||dy>=B||dx>=A||flag[dx][dy][dz]||a[dx][dy][dz])
continue;
flag[dx][dy][dz]=1;
ne.x=dx;
ne.y=dy;
ne.z=dz;
ne.step=now.step+1;
q.push(ne);
}
}
printf("-1\n");
}
{
int i,j,k,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&A,&B,&C,&t);
for(i=0; i<A; i++)
{
for(j=0; j<B; j++)
{
for(k=0; k<C; k++)
scanf("%d",&a[i][j][k]);
}
}
bfs();
}
return 0;
}
hdoj1253的更多相关文章
- HDOJ1253 胜利大逃亡 BFS
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
随机推荐
- Struts2 (三) (转载)
前面一直在说Action可以是一个普通的Java类,与Servlet API完全分离,但是为了实现业务逻辑,Action需要使用HttpServletRequest内容.Struts 2设计的精巧之处 ...
- 一款很好的日程安排插件fullcalendar 非常适合OA等系统
1.插件下载 http://arshaw.com/fullcalendar/download/ 2. <!DOCTYPE html> <meta http-equiv="C ...
- ssh key 生成
1.设置好git的name和email $ git config --global user.name "姓名" $ git config --global user.email ...
- Android Touch事件分发
跟touch事件相关的3个方法: public boolean dispatchTouchEvent(MotionEvent ev); //用来分派event public boolean onInt ...
- 查看ubuntu磁盘空间占用及占用空间大的文件
最近老是收到 ecs上有台服务器的磁盘利用率高 终于有一天 ssh登不上去了 http://blog.csdn.net/aaashen/article/details/50685988 清除相关大文件 ...
- 机器学习:Principal components analysis (主分量分析)
Principal components analysis 这一讲,我们简单介绍Principal Components Analysis(PCA),这个方法可以用来确定特征空间的子空间,用一种更加紧 ...
- 理解 Android Fragment
/***************************************************************************************** * 理解 Andr ...
- RAutomation 在 Watir中的使用
RAutomation的用法 require "rautomation" # 通过匹配部分标题来获取窗口 window = RAutomation::Window.new(:tit ...
- opencv3.4.0 安装过程中出现的问题
重新安装opencv3.4.0 参考安装博客: opencv 安装版本测试:pkg-config --modversion opencv https://blog.csdn.net/cocoaqin/ ...
- SNE降维与可视化
from sklearn import datasets digits = datasets.load_digits(n_class=5) X = digits.data y = digits.tar ...