POJ - 3984 迷宫问题 dfs解法
#include<stdio.h>
#include<string.h>
#include<stack>
#include<algorithm>
using namespace std;
stack<int>s1,s2;
int a[][],b[][];
int di[][]={,,,-,-,,,};
int judge(int x,int y)
{
return x>=&&x<&&y>=&&y<&&a[x][y]==&&!b[x][y];
}
int dfs(int x,int y)
{
if(x==&&y==)
{
s1.push(x);s2.push(y);
return ;
}
b[x][y]=;
if(judge(x+,y)&&dfs(x+,y)||judge(x,y-)&&dfs(x,y-)||judge(x,y+)&&dfs(x,y+)||judge(x-,y)&&dfs(x-,y))
{
s1.push(x);s2.push(y);
return ;
}
else return ;
return ;
}
void print()
{
while(!s1.empty())
{
printf("(%d, %d)\n",s1.top(),s2.top());
s1.pop();s2.pop();
}
} int main()
{
int i,j;
for(i=;i<;i++)
for(j=;j<;j++)
scanf("%d",&a[i][j]);
memset(b,,sizeof(b));
dfs(,);
print();
return ;
}
POJ - 3984 迷宫问题 dfs解法的更多相关文章
- poj 3984 迷宫问题(dfs)
题目链接:http://poj.org/problem?id=3984 思路:经典型的DFS题目.搜索时注意剪枝:越界处理,不能访问处理. 代码: #include <iostream> ...
- POJ - 3984 迷宫问题 bfs解法
#include<stdio.h> #include<string.h> #include<algorithm> #include<stack> usi ...
- BFS(最短路+路径打印) POJ 3984 迷宫问题
题目传送门 /* BFS:额,这题的数据范围太小了.但是重点是最短路的求法和输出路径的写法. dir数组记录是当前点的上一个点是从哪个方向过来的,搜索+,那么回溯- */ /************* ...
- POJ 3984 迷宫问题
K - 迷宫问题 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- POJ 3984 迷宫问题(简单bfs+路径打印)
传送门: http://poj.org/problem?id=3984 迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ - 3984 - 迷宫问题 (DFS)
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10936 Accepted: 6531 Description ...
- POJ - 3984迷宫问题(最短路径输出)
题目链接:http://poj.org/problem?id=3984 题目: 迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- POJ 3984 迷宫问题 bfs 难度:0
http://poj.org/problem?id=3984 典型的迷宫问题,记录最快到达某个点的是哪个点即可 #include <cstdio> #include <cstring ...
随机推荐
- xsy子矩形
考虑一种解题方法,枚举上下边界L,R, 然后二分答案T,我们要判断的是否存在 \[ \frac{(sum_j - sum_i)}{2 * (R - L + 1 + j - i)} \ge T \] 也 ...
- [UnityShader基础]04.ColorMask
语法如下: ColorMask RGB | A | 0 | 其他R,G,B,A的组合 ColorMask R,意思是输出颜色中只有R通道会被写入 ColorMask 0,意思是不会输出任何颜色 默认值 ...
- 关于spring的一些注解
- SQL Server 中的6种事务隔离级别简单总结
本文出处:http://www.cnblogs.com/wy123/p/7218316.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...
- 吴裕雄 python深度学习与实践(13)
import numpy as np import matplotlib.pyplot as plt x_data = np.random.randn(10) print(x_data) y_data ...
- hbase--知识点总结2
--用java操作hbase 1.配置jar包环境 创建hbase项目 --> 新建folder文件夹 --> 将hbase相关jar包全部导入到java项目之中 --> add b ...
- 搭建EOS环境
[搭建EOS环境] 1.Ubuntu 18.04 下安装eosio wget https://github.com/eosio/eos/releases/download/v1.4.4/eosio_1 ...
- Nginx – rewrite 配置 URL重写及301跳转原理图
Nginx – rewrite 配置 URL重写 官网:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html 语法:rewrite re ...
- Linux磁盘配额
Step1:修改fstab文件,增加磁盘限额用户和用户组信息 # /etc/fstab# Created by anaconda on Sat Dec 29 04:48:18 2018## Acces ...
- jq怎么给图片绑定上传文件按钮
html代码 <img src="/img/zhengmian.png" alt="" class="file1"> <i ...