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

解题报告:

1、设置node结构体,成员pre记录该点的前驱。

2、递归输出:

void print(int i)
{
if(q[i].pre!=-)
{
print(q[i].pre);
printf("(%d, %d)\n",q[i].x,q[i].y);
}
}
int MAP[][];
int front=;
int rear=; int mov[][]={{,},{-,},{,},{,-}}; struct node{
int x,y;
int pre;///从左上角到右下角的每一个元素的,前一个元素的位置,即保存路径;
}q[]; void print(int i)
{
if(q[i].pre!=-)
{
print(q[i].pre);
printf("(%d, %d)\n",q[i].x,q[i].y);
}
} void bfs(int x1,int y1)
{
q[front].x=x1;
q[front].y=y1;
q[front].pre=-;
while(front<rear)
{
for(int k=;k<;k++)
{
int tx=q[front].x+mov[k][];
int ty=q[front].y+mov[k][];
if(tx<||tx>||ty<||ty>||MAP[tx][ty])
continue;
else
{
MAP[tx][ty]=;
q[rear].x=tx;
q[rear].y=ty;
q[rear].pre=front;
rear++;
}
if(tx==&&ty==)
{
print(front);
return ;
}
}
front++;
}
} int main()
{
for(int i=;i<;i++)
for(int j=;j<;j++)
scanf("%d",&MAP[i][j]);
printf("(%d, %d)\n",,);
bfs(,);
printf("(%d, %d)\n",,);
return ;
}

简单广搜,迷宫问题(POJ3984)的更多相关文章

  1. POJ 3126 Prime Path 简单广搜(BFS)

    题意:一个四位数的质数,每次只能变换一个数字,而且变换后的数也要为质数.给出两个四位数的质数,输出第一个数变换为第二个数的最少步骤. 利用广搜就能很快解决问题了.还有一个要注意的地方,千位要大于0.例 ...

  2. 广搜 迷宫(zznu 1962)

    http://acm.zznu.edu.cn/problem.php?id=1962 题目描述 在很多 RPG (Role-playing Games) 游戏中,迷宫往往是非常复杂的游戏环节.通常来说 ...

  3. POJ1376简单广搜

    题意:       给你一个n*m的矩阵,然后给你机器人的起点和终点,还有起点的方向,然后每次机器人有两种操作,左右旋转90度,或者是朝着原来的方向走1,2或者3步,机器人再走的过程中不能碰到格子,也 ...

  4. hdu 2612(Find a way)(简单广搜)

    Find a way Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Su ...

  5. (简单广搜) Ice Cave -- codeforces -- 540C

    http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...

  6. poj 3278:Catch That Cow(简单一维广搜)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45648   Accepted: 14310 ...

  7. hdu 2612:Find a way(经典BFS广搜题)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  9. HDU 1253 (简单三维广搜) 胜利大逃亡

    奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...

随机推荐

  1. gitignore 忽略某文件夹下 非某后缀名的文件

    忽略指定文件夹下的除某一文件之外的其他文件 parent_dir/!spec_file_name.html 忽略指定文件夹下的除某一类后缀名的文件 parent_dir/*[!*.html] 注意:若 ...

  2. 「linux」后台启动nohup经常跟的>/dev/null 2>&1是什么意思

    https://www.cnblogs.com/wangsongbai/p/10215155.html 我们在写启动脚本的时候,会用nohup &,这个大家都知道,但是经常会有 >/de ...

  3. hadoop "startdfs.sh" WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

    这个waring 信息是可以忽略的.下面是解决方案 在hadoop-env.sh中添加 export HADOOP_OPTS="$HADOOP_OPTS -Djava.library.pat ...

  4. 前端面试题 ---- html篇

    想要换工作了,转载自https://www.cnblogs.com/zhangshuda/p/8464772.html,感谢原博主. 一.html 1.html和xhtml区别 1. html:超文本 ...

  5. ctrip-apollo

    云端多网卡问题: 参考:https://blog.csdn.net/buyaore_wo/article/details/79847404

  6. (转)AIX修改系统时区的3种方法和AIX 时间问题(夏令时)

    原文:http://blog.csdn.net/fuwencaho/article/details/28267283 http://www.wo81.com/tec/os/aix/2014-04-30 ...

  7. ip地址在通信中的变化(就简单的讲一下, 给自己mark)

    节点之间的通信 数据报文的封装(自上而下) http tcp ip mac(讯框) 数据报文的源ip和目标ip是不变的(在内网中, 如果考虑到连接到外部网路的时候, 如果有路由器(里面有嵌入式的Lin ...

  8. SQL DATEDIFF语法及时间函数 Sql 查询当天、本周、本月记录

    SQL DATEDIFF语法及时间函数 Sql 查询当天.本周.本月记录 转:http://blog.csdn.net/Json1204/article/details/7863801?locatio ...

  9. mybatis问题记录

    问题:2019年3月29日 23:46:24 org.apache.ibatis.builder.IncompleteElementException: Could not find result m ...

  10. 内存分配详解 malloc, new, HeapAlloc, VirtualAlloc,GlobalAlloc

    很多地方都会使用内存,内存使用过程中操作不当就容易崩溃,无法运行程序,上网Google学习一下,了解整理下他们之间的区别以及使用 ,获益匪浅 0x01 各自的定义和理解 (1)先看GlobalAllo ...