题目链接: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. Troubleshooting ORA-201 and ORA-202 Error

    ---- 3. When lowering the value of COMPATIBLE: You cannot start the database with lower compatibilit ...

  2. js学习笔记 -- Promise

    Promise new Promise( function(resolve, reject) {...} /* executor */  ); executor是带有 resolve 和 reject ...

  3. JQuery 判断滚动条是否到底部

    BottomJumpPage: function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).he ...

  4. 数据库版本管理工具flyway

    引入flyway_core  jar包 java 代码实现 public class FlywayMigration { @Resource private DataSource dataSource ...

  5. C. Permute Digits dfs大模拟

    http://codeforces.com/contest/915/problem/C 这题麻烦在前导0可以直接删除,比如 1001 100 应该输出11就好 我的做法是用dfs,每一位每一位的比较. ...

  6. 3DSMAX安装失败如何完全卸载

    安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).AUTODESK系列软件着实令人头疼,有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  7. 监听outlook新邮件

    using System; using System.Linq; using Microsoft.Office.Interop.Outlook; using System.Collections.Ge ...

  8. Kudu Tablet design

    不多说,直接上干货! http://blog.csdn.net/lookqlp/article/details/51416829

  9. java 数字进制之间转换

    //10进制转换 16进制 System.out.println(Integer.toHexString(val)); System.out.println(String.format("% ...

  10. C++ 虚函数、纯虚函数、虚继承

    1)C++利用虚函数来实现多态. 程序执行时的多态性通过虚函数体现,实现运行时多态性的机制称爲动态绑定:与编译时的多态性(通过函数重载.运算符重载体现,称爲静态绑定)相对应. 在成员函数的声明前加上v ...