原题链接

思路:水题,直接搜

 #include "map"
#include "queue"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#define abs(x) x > 0 ? x : -x
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b using namespace std; int z2,x2,y2,n;
int d[][]= {{,,},{,,},{,,-},{,-,},{,,},{-,,}};
bool Map[][][],vis[][][]; struct Node{
int zz,xx,yy;
int step;
}; void Bfs(int z,int x,int y)
{
memset(vis,,sizeof(vis));
queue<Node>Q;
Node now,next; now.zz = z;
now.xx = x;
now.yy = y;
now.step = ;
vis[z][x][y] = ; Q.push(now); while(!Q.empty())
{
now = Q.front();
Q.pop(); if(now.zz==z2 && now.xx==x2 && now.yy==y2)
{
printf("%d %d\n",n,now.step);
return;
} for(int i=; i<; i++)
{
next.zz = now.zz + d[i][];
next.xx = now.xx + d[i][];
next.yy = now.yy + d[i][];
next.step = now.step + ; if(Map[next.zz][next.xx][next.yy] && !vis[next.zz][next.xx][next.yy])
{
vis[next.zz][next.xx][next.yy] = ;
Q.push(next);
}
}
}
printf("NO ROUTE\n");
} int main()
{
int x1,y1,z1,i,j,k;
char s[],c;
while(~scanf("%s%d",s,&n))
{
memset(Map,,sizeof(Map));
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
getchar();
for(k=; k<=n; k++)
{
scanf("%c",&c);
if(c=='O')
Map[i][j][k] = ;
if(c=='X')
Map[i][j][k] = ;
}
} scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
z1+=,x1+=,y1+=,z2+=,x2+=,y2+=;
getchar();
gets(s); Bfs(z1,x1,y1);
}
return ;
}

hdu1240 bfs 水题的更多相关文章

  1. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  2. POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)

    http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...

  3. nyoj--523--亡命逃窜(BFS水题)

    亡命逃窜 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...

  4. POJ3287(BFS水题)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  5. POJ 3126 Prime Path bfs, 水题 难度:0

    题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...

  6. codeforces 811 D. Vladik and Favorite Game(bfs水题)

    题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子, ...

  7. CYJian的水题大赛

    实在没忍住就去打比赛了然后一耗就是一天 最后Rank19还是挺好的(要不是乐多赛不然炸飞),这是唯一一套在Luogu上号称水题大赛的而实际上真的是水题大赛的比赛 好了我们开始看题 T1 八百标兵奔北坡 ...

  8. hihocoder 1322 - 树结构判定 - [hiho一下161周][模板题/水题]

    题目链接:http://hihocoder.com/problemset/problem/1322 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个包含 N 个顶 ...

  9. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

随机推荐

  1. 免费电子书:C#代码整洁之道

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:<Clean Code(代码整洁之道)>是一本经典的著作,那么对于编写整洁 ...

  2. jBox使用记录

    1.不显示底部按钮,可以将buttons设置为buttons:{} 例:$.jBox.open("iframe:http://www.baidu.com", "百度一下& ...

  3. json对象的解析

    json对象数据: { "status": "200", "code": "", "msg": &q ...

  4. free store VS heap(自由存储区VS堆)

    1. free store VS heap free store (自由存储区)和 heap (堆),在C/C++中经常会遇到.他们是否有区别呢? 偶最早发现这两个概念性问题是在<Excepti ...

  5. python 多态

    多态 类具有继承关系,并且子类类型可以向上转型看做父类类型,如果我们从 Person 派生出 Student和Teacher ,并都写了一个 whoAmI() 方法: class Person(obj ...

  6. Liferay 6.2 改造系列之二十四:修改liferay密码的加密方式

    为了便于后期与Cas集成过程中使用数据库用户的方便,将liferay密码的加密方式改为SHA. 在/portal-master/portal-impl/src/portal.properties配置文 ...

  7. .net自动生成数据库表的类

    // 获取到所有的用户表.DataTable userTableName = GetTable( "select name as tablename from sysobjects wher ...

  8. 2016.5.27 php测试中敏感度高,怎么调整

    在测试PHP代码的过程中,会遇到这样的问题:PHP提示Notice: Undefined variable,遇到这样的问题很纠结,但是很容易解决. 今天晚上,我就遇到了这样的问题,到网上搜索了很多解决 ...

  9. psql-07表:分区表

    表继承与分区表 表继承 表继承是PostgreSQL特有的 create table persons ( age int, sex boolean ); create table students ( ...

  10. BestCoder Round #74 (div.2)

    组合 1001 LCP Array 第一题就小难,出题的好像是浙大的大牛? 找到一个规律:a[i] = x, s[i..i+x]都想同.a[i] = a[i+1] + 1 (a[i] > 0), ...