简单广搜,迷宫问题(POJ3984)
题目链接: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)的更多相关文章
- POJ 3126 Prime Path 简单广搜(BFS)
题意:一个四位数的质数,每次只能变换一个数字,而且变换后的数也要为质数.给出两个四位数的质数,输出第一个数变换为第二个数的最少步骤. 利用广搜就能很快解决问题了.还有一个要注意的地方,千位要大于0.例 ...
- 广搜 迷宫(zznu 1962)
http://acm.zznu.edu.cn/problem.php?id=1962 题目描述 在很多 RPG (Role-playing Games) 游戏中,迷宫往往是非常复杂的游戏环节.通常来说 ...
- POJ1376简单广搜
题意: 给你一个n*m的矩阵,然后给你机器人的起点和终点,还有起点的方向,然后每次机器人有两种操作,左右旋转90度,或者是朝着原来的方向走1,2或者3步,机器人再走的过程中不能碰到格子,也 ...
- hdu 2612(Find a way)(简单广搜)
Find a way Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- (简单广搜) Ice Cave -- codeforces -- 540C
http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...
- poj 3278:Catch That Cow(简单一维广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45648 Accepted: 14310 ...
- hdu 2612:Find a way(经典BFS广搜题)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- poj 3984:迷宫问题(广搜,入门题)
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7635 Accepted: 4474 Description ...
- HDU 1253 (简单三维广搜) 胜利大逃亡
奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...
随机推荐
- WIN2008R2 asp.net core的配置
配置IIS Windows Server上通过“添加角色和功能”,桌面Windows上通过“启用和关闭Windows功能”来安装和配置IIS.确保勾选Web服务和“IIS 管理控制台”: Window ...
- Web前端常见问题
一.理论知识 1.1.讲讲输入完网址按下回车,到看到网页这个过程中发生了什么 a. 域名解析 b. 发起TCP的3次握手 c. 建立TCP连接后发起http请求 d. 服务器端响应http请求,浏览器 ...
- Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061) ----Hive schematool -initSchema -dbType mysql
schematool -initSchema -dbType mysqlMetastore connection URL: jdbc:mysql://localhost/metastore_db?cr ...
- 转 使用SwingBench 对Oracle RAC DB性能 压力测试
###########说明1: 1 Swingbench 简述 1.1 概述 这是Oracle UK的一个员工在一个被抛弃的项目的基础上开发的.目前稳定版本2.2,最新版本2.3,基于JDK1.5.该 ...
- powerdesigner 遇到的各种问题总结
1. 设置自增 打开表 -- 在具体列的前面双击即可添加各种属性 2. 生成sql 时设置编码 database --> generate database --> format --&g ...
- python fork函数
import os print('---父进程id:%s----'%(os.getpid())) pid=os.fork()#只能在liunx环境下执行 print('---%s---' % (os. ...
- GRE新东方推荐学习方法(2010年左右)
单词:新东方新版红宝书(<NEW GRE 词汇精选>),不用<再要你命三个> 填空:新东方绿皮书(扎实的词汇量) 阅读:1 新东方绿皮书:2 <GRE阅读 39+3全攻略 ...
- 性能测试工具Jmeter07-Jmeter性能测试实战
测试需求:测试20个用户访问www.baozhenart.com在负载达到30QPS时的平均响应时间 QPS:Query Per Second每秒查询率.是一台查询服务器每秒能够处理的查询次数.在因特 ...
- WSGI学习系列Paste
Paste has been under development for a while, and has lots of code in it. The code is largely decoup ...
- Python 的命名空间
Python命名空间的本质: 一.命名空间的定义: 二.命名空间的查找顺序: 三.命名空间的生命周期: 四.通过locals()和globals() BIF访问命名空间. 重点是第四部分,我们将在此部 ...