原题链接

思路:水题,直接搜

 #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. RAC的QA

    RAC: Frequently Asked Questions [ID 220970.1]   修改时间 13-JAN-2011     类型 FAQ     状态 PUBLISHED   Appli ...

  2. VS2010和matlab2010混合编程中char16_t重定义的问题

    原因是VS2010中的yvals.h添加了char16_t的定义,而Matlab的matrix.h也包含对char16_t的定义,所以同时包含这两个头文件的话,会导致重复定义char16_t的错误.只 ...

  3. mysql 方法row_number()方法

    1.  SELECT  t.*,        @curRow := @curRow + 1 AS row_numberFROM    structure tJOIN    (SELECT @curR ...

  4. Android:dimen尺寸资源文件的使用(转)

    为了适配不同的分辨率. dimen.xml在values文件夹下面 <resources> <!-- Default screen margins, per the Android ...

  5. C# 获取wave文件信息【转】

    public class WaveHelper { /// <summary> /// 数据流 /// </summary> private Stream m_WaveData ...

  6. 数字信号处理实验(五)——IIR滤波器的设计

    一.使用自编函数设计IIR滤波器 1.冲激响应法 (1)注给出的数字滤波器指标先化成模拟指标 (2)设计出模拟滤波器: (3)使用冲激响应法转化成数字滤波器 (4)一个demo clear all; ...

  7. 第一个vs2013控制台程序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 改变图片尺寸(python)

    for name in /图片路径; do convert -resize 256x256! $name $namedone

  9. 51nod 1051 求最大子矩阵和

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1051 1051 最大子矩阵和 基准时间限制:2 秒 空间限制: ...

  10. hdu1160 LIS变形

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 题意:两个子序列 一个是升序,一个是降序,求最长的子序列是多长,并输出路径.(答案不 ...