题目链接:http://poj.org/problem?id=3984

宽度优先搜索最短路径的记录和打印问题

 #include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std; bool maze[][];
int go[][] = {,,,-,,,-,};
struct node
{
int x,y;
int prex,prey;
}path[][],temp; void bfs()
{
queue<node> Q;
node temp;
int nx,ny;
path[][].x=path[][].y=;
Q.push(path[][]);
while(!Q.empty())
{
temp = Q.front();
Q.pop();
if(temp.x==&&temp.y==)
return;
for(int i=;i<;i++)
{
nx = temp.x + go[i][];
ny = temp.y + go[i][];
if(nx>=&&nx<&&ny>=&&ny<&&!maze[nx][ny])
{
path[nx][ny].x = nx;
path[nx][ny].y = ny;
path[nx][ny].prex = temp.x;
path[nx][ny].prey = temp.y;
maze[nx][ny] = ;
Q.push(path[nx][ny]);
}
}
}
} void print_path(int x,int y)
{
if(x==&&y==)
{
cout<<"("<<path[][].x<<", "<<path[][].y<<")"<<endl;
return ;
}
int px = path[x][y].prex;
int py = path[x][y].prey;
print_path(px,py);
cout<<"("<<path[x][y].x<<", "<<path[x][y].y<<")"<<endl;
}
int main()
{
for(int i=;i<;i++)
for(int j=;j<;j++)
scanf("%d",&maze[i][j]);
bfs();
print_path(,);
return ;
}

[POJ 3984] 迷宫问题(BFS最短路径的记录和打印问题)的更多相关文章

  1. POJ 3984 迷宫问题 (BFS + Stack)

    链接 : Here! 思路 : BFS一下, 然后记录下每个孩子的父亲用于找到一条路径, 因为寻找这条路径只能从后向前找, 这符合栈的特点, 因此在输出路径的时候先把目标节点压入栈中, 然后不断的向前 ...

  2. POJ - 3984迷宫问题(最短路径输出)

    题目链接:http://poj.org/problem?id=3984 题目: 迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

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

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

  4. POJ 3984 迷宫问题 bfs 难度:0

    http://poj.org/problem?id=3984 典型的迷宫问题,记录最快到达某个点的是哪个点即可 #include <cstdio> #include <cstring ...

  5. POJ - 3984 迷宫问题 BFS求具体路径坐标

    迷宫问题 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...

  6. poj 3984 迷宫问题 bfs

    学会这道水题之后我懂得了不少哈,首先水题也能学到不少知识,尤其像我这样刚入门的小菜鸟,能学到一些小技巧. 然后就是可以从别人的代码里学到不一样的思路和想法. 这题就是求最短的路径,首先想到就是用bfs ...

  7. POJ - 3984 迷宫问题 bfs解法

    #include<stdio.h> #include<string.h> #include<algorithm> #include<stack> usi ...

  8. BFS(最短路+路径打印) POJ 3984 迷宫问题

    题目传送门 /* BFS:额,这题的数据范围太小了.但是重点是最短路的求法和输出路径的写法. dir数组记录是当前点的上一个点是从哪个方向过来的,搜索+,那么回溯- */ /************* ...

  9. POJ 3984 迷宫问题(简单bfs+路径打印)

    传送门: http://poj.org/problem?id=3984 迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

随机推荐

  1. 如何重置Sitecore CMS中的管理员密码

    在Sitecore项目上工作时,有时管理员凭据会丢失或损坏.在这些情况下,重新获得快速访问权限以便不中断开发非常重要. 对Core数据库运行以下查询,您将能够admin/b再次使用以下命令登录Site ...

  2. 【Hive学习之三】Hive 函数

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...

  3. linux帮助

    不知道的指令但是你想要了解:man 指令 如果知道某一个指令忘记相关参数:在指令后接 -- help 忘记指令: 两个tab

  4. pip使用简要说明

    一.pip常用命令 安装指定包 pip install SomePackage #最新版本 安装指定包 pip install SomePackage==1.0.4 #指定版本 安装指定包 pip i ...

  5. golang学习笔记14 golang substring 截取字符串

    golang学习笔记14 golang substring 截取字符串golang 没有java那样的substring函数,但支持直接根据 index 截取字符串mystr := "hel ...

  6. C#——WebApi 接口参数传参详解

    本篇打算通过get.post.put.delete四种请求方式分别谈谈基础类型(包括int/string/datetime等).实体.数组等类型的参数如何传递. 一.get请求 对于取数据,我们使用最 ...

  7. jdbc连接oracle数据库问题

    下面是JDBC连接oracle数据库流程: String dbURL = "jdbc:oracle:thin:@url:1521:service_name"; String use ...

  8. Linux下的Jmeter运行测试

    本文主要介绍Jmeter脚本如何在Linux通过no GUI的方式运行.总共分三部分: 1.Linux下JDK的安装及环境变量的配置 2.Linux下Jmeter的安装及环境变量的配置 3.运行结果的 ...

  9. Java中的ASCII码与Unicode码

    先上代码 后续更新 public class Unicode { public static void main(String[] args) { char ch1 = 'c'; char ch2 = ...

  10. 2019/3/25 wen 包,对象的行为