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 ...
随机推荐
- C# GetHashCode 的实现方式
在项目中,在使用哈希表时.有时会须要Override GetHashCode. 这里给出一种普遍的做法: 版本号1:实现一个helper.传递类型T.返回这个类型的hashcode.函数逻辑非常直接, ...
- ajax跨域请求的问题
使用getJson跨域请求,需要向服务器发送一个参数callback=? $.getJSON("http://appcenter.mobitide.com/admin/appSearch.p ...
- The server must be started under an unprivileged user ID to prevent
mysql8 PostgreSQL [root@test local]# postgres -D /usr/local/pgsql/data"root" execution of ...
- 5.JavaScript改变样式,验证用户输入
① x=document.getElementById("demo") //找到元素 x.style.color="#ff0000"; //改变样式 ② if ...
- return;测试
一 没有return;,则会顺序执行到最后 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- Web app root system property already set to different value: 'webapp.root'
java.lang.IllegalStateException: Web app root system property already set to different value: 'webap ...
- 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习
ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding va ...
- Linux_基于Docker快速搭建个人博客网站
时间:2017年04月28日星期五 说明:基于docker技术,使用jpress开源框架搭建个人博客网站.特别感谢jpress开源项目.系统版本:CentOS 7.2-64bit. 步骤一:准备Doc ...
- syslog格式
转自:http://wly719.iteye.com/blog/1827394 1.syslog格式介绍 在Unix类操作系统上,syslog广泛 应用于系统日志.syslog日志消息既可以记录在本地 ...
- 用python做自动化测试--Python实现远程性能监控
http://blog.csdn.net/powerccna/article/details/8044222 在性能测试中,监控被测试服务器的性能指标是个重要的工作,包括CPU/Memory/IO/N ...