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

思路:经典型的DFS题目。搜索时注意剪枝:越界处理,不能访问处理。

代码:

#include <iostream>
using namespace std; const int MAX_N = ;
int map[MAX_N][MAX_N];
typedef struct Node
{
int x;
int y;
}Road;
Road vis[MAX_N]; int SearchRoad( int i, int j, int count )
{
if ( i == && j == )
{
vis[count].x = i;
vis[count].y = j;
for ( int i = ; i <= count; ++i )
printf( "(%d, %d)\n", vis[i].x, vis[i].y );
}
else
if ( i >= || j >= || map[i][j] == )
return ;
else
{
vis[count].x = i;
vis[count].y = j; count++;
SearchRoad( i+, j, count );
SearchRoad( i, j+, count );
} return ;
} int main()
{
for ( int i = ; i < ; ++i )
for ( int j = ; j < ; ++j )
scanf( "%d", &map[i][j] ); SearchRoad( , , );
return ;
}

poj 3984 迷宫问题(dfs)的更多相关文章

  1. POJ - 3984 迷宫问题 dfs解法

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

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

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

  3. POJ 3984 迷宫问题

    K - 迷宫问题 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

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

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

  5. POJ - 3984 - 迷宫问题 (DFS)

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

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

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

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

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

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

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

  9. [POJ 3984] 迷宫问题(BFS最短路径的记录和打印问题)

    题目链接:http://poj.org/problem?id=3984 宽度优先搜索最短路径的记录和打印问题 #include<iostream> #include<queue> ...

随机推荐

  1. CSS–Some Structure

    Some Structure About CSS Layout Position,Layer[层次] Box Model Visual Formatting Model BFC[block forma ...

  2. ajax post传值

    一.字符串             $.ajax({                type: "POST",                data: {"ID&quo ...

  3. deque(双端队列)

    deque 是对queue的改进,增加了 push_front 和 pop_front 函数 , 和 双向链表作用差不多: 这里就不多讲了.可以参考: List(双向链表)

  4. ASP.NET MVC Framework

    ASP.NET MVC Framework是微软在ASP.NET中所添加的一组类库,这组类库可以使用Model-View-Controller的设计模式来开发ASP.NET的应用程序.它与现有的ASP ...

  5. Bootstrap第一天

    1.代码引入: 第一步:在html5文档 <meta name="viewport" content="width=device-width, initial-sc ...

  6. .net 和java JSON 模板

    1..net 中JSON对象格式模板 //  JSON键值对格式:'key':'value'  public static string FORMAT_KEYVALUE = "\" ...

  7. php基础知识(很简单一套适合零基础的朋友学习)

    红色的一般都是重点,还有自己的一些废话 运算符 算术运算符: 基本运算(除数不能为0) 比较运算符: 大小比较(类型比较), 如果两个类型不一样,系统会自动转换成统一类型 赋值运算符: 基本赋值和运算 ...

  8. PHP学习笔记5-类的继承/方法重写

    更改Man.php文件名为People.php,加入代码: public function hi(){ return $this->_name.' say hi'; } 新建文件Man.php: ...

  9. [LeetCode]题解(python):105-Construct Binary Tree from Preorder and Inorder Traversal

    题目来源: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题意分析: ...

  10. 转: 关于viewport的理解

    最近我做了一点儿针对手机的Web开发和相关研究.按说,Web自设计之初,就已经考虑了设备无关性.然而,现实总是不尽如人意. 我们知道大多数网页都是针对桌面显示器开发和测试的,但是手机屏幕通常要比桌面显 ...