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 ...
随机推荐
- 【阿里云服务器】外网无法访问tomcat下部署的项目
问题提出:在ESC实例上部署了jdk和tomcat(略,上云了,上云了),启动tomct后,内网可以访问8080端口,外网无法访问8080. 系统环境:winsdow 2008 企业版 解决方案: 在 ...
- pyton unittest
在说unittest之前,先说几个概念: TestCase 也就是测试用例 TestSuite 多个测试用例集合在一起,就是TestSuite TestLoader是用来加载TestCase到Test ...
- web应用 与 http协议
一.web 应用 Web应用程序是一种可以通过Web访问的应用程序,用户只需要有浏览器即可访问应用程序,不需要再安装其他软件. 应用程序有两种模式C/S.B/S.C/S即客户端—服务端程序这类程序一般 ...
- 【机器学习_5】Anaconda:初学Python、入门机器学习的首选
Anaconda是一个用于科学计算的Python发行版,提供了包管理与环境管理的功能,可以很方便地解决多版本python并存.切换以及各种第三方包安装问题. 集成包功能: NumPy:提供了矩阵运算的 ...
- Unity3D AssetBundle相关
Unity3D AssetBundle相关 首先,先看一下原理吧 Unity3D研究院之Assetbundle的原理(六十一) 其次,接着往下看:Unity3D研究院之Assetbundle的实战( ...
- AD+DMA+USART实验中的收获和总结
由于实验室用的是USART3接口,但是在基地实验时,由于没有RS232,只能换到USART1,进行实验.(在交作业的时候,记得要再换回去) 在这个过程中,遇到困难,用串口软件发送数据时无响应,应该意味 ...
- VS2015秘钥
Visual Studio Professional 2015简体中文版(专业版)KEY:HMGNV-WCYXV-X7G9W-YCX63-B98R2Visual Studio Enterprise 2 ...
- input text 只能输入数字
添加 onkeyup="value=value.replace(/[^\d]/g,'')"
- swift 监测内存泄漏 MLeaksFinder
使用MLeaksFinder检测项目内存泄露总结 https://www.cnblogs.com/ocarol/p/5288497.html
- Eclipse Java注释模板设置
类型(Types)注释标签(类的注释): /** * @ClassName: ${type_name} * @Description: ${todo}(这里用一句话描述这个类的作用) * @autho ...