迷宫bfs POJ3984
#include<stdio.h> int map[5][5]={0,1,0,0,0, 0,1,0,1,0, 0,0,0,0,0, 0,1,1,1,0, 0,0,0,1,0}; int mx[4]={1,-1,0,0}; int my[4]={0,0,1,-1}; int q; typedef struct node { int x; int y; int step; int pre; }node; node dui[100]; int tou=0; int wei=1; void bfs() { int nx; int ny; dui[tou].x=0; dui[tou].y=0; dui[tou].step=1; dui[tou].pre =-1; map[0][0]=0; while(tou<wei) { if(dui[tou].x ==4&&dui[tou].y==4) { q=tou; printf("%d\n",dui[tou].step); break; } for(int i=0;i<4;i++) { nx=dui[tou].x +mx[i]; ny=dui[tou].y +my[i]; if(nx>=0&&nx<5&&ny>=0&&ny<5&&map[nx][ny]==0) { dui[wei].x =nx; dui[wei].y =ny; dui[wei].step =dui[tou].step +1; map[nx][ny]=dui[tou].step +1; dui[wei].pre =tou; wei++; } } tou++; }
} void prin(int i) { if(i==-1) return; prin(dui[i].pre ); printf("(%d,%d)\n",dui[i].x ,dui[i].y ); } int main() { bfs(); prin(q); return 0; }
迷宫bfs POJ3984的更多相关文章
- ZOJ 1649 Rescue(有敌人迷宫BFS)
题意 求迷宫中从a的位置到r的位置须要的最少时间 经过'.'方格须要1s 经过'x'方格须要两秒 '#'表示墙 因为有1s和2s两种情况 须要在基础迷宫bfs上加些推断 令到达每一个点的时间初 ...
- bfs—迷宫问题—poj3984
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20591 Accepted: 12050 http://poj ...
- 迷宫问题---poj3984(bfs,输出路径问题)
题目链接 主要就是输出路径问题: pre[x][y]表示到达(x,y)是由点(pre[x][y].x, pre[x][y].y)而来: #include<stdio.h> #includ ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- 暑假集训(1)第八弹 -----简单迷宫(Poj3984)
Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, ...
- poj 1383 Labyrinth【迷宫bfs+树的直径】
Labyrinth Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 4004 Accepted: 1504 Descrip ...
- hdu_1728_逃离迷宫(bfs)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意:走迷宫,找最小的拐角 题解:对BFS有了新的理解,DFS+剪枝应该也能过,用BFS就要以拐 ...
- hdu 1728 逃离迷宫 (BFS)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- HDU1728-逃离迷宫-BFS
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- hdu 2184 01背包变形
转自:http://blog.csdn.net/liuqiyao_01/article/details/8753686 题意:这是又是一道01背包的变体,题目要求选出一些牛,使smartness和fu ...
- Struts2的@ResultPath
转自:http://blog.csdn.net/yandufeng/article/details/8105495 这里我要补充一下:要理解Annotation,最好的方法还是看源码,struts中c ...
- 谈敏捷,谈开发 --《Agile Software Development》读后感
谈敏捷,谈开发 --<Agile Software Development>读后感 北航计算机学院 110616班 11061171 毛宇 联系方式:maoyu815930@sina.co ...
- Android ImageView图片自适应 (转)
网络上下载下来的图片自适应:android:adjustViewBounds="true"(其详细解释在下面)<ImageView android:id=" ...
- CC2540开发板学习笔记(七)—— 睡眠唤醒
(一)中断唤醒 一.实验内容 通过中断唤醒在睡眠模式下的CC2540 二.实验原理 1.系统电源管理(工作方式) (1)全功能模式: 高频晶振(16M或者32M)和低频晶振(32.768K RCOSC ...
- XStream 快速转换xml
项目地址:http://xstream.codehaus.org/tutorial.html (以下来源于官网) 1.Create classes to be serialized(初始化类) pub ...
- Fragments碎片
A Fragment represents a behavior or a portion of user interface in an Activity. 在一个Activity活动中,一个Fra ...
- PHP 输出表格单元格的数据之用表单的方式;
echo "<table border=1 class="imagetable" >"; //使用表格格式化数据echo "<for ...
- Python实践:提取文章摘要
一.概述 二.纯文本摘要 三.HTML摘要 一.概述 在博客系统的文章列表中,为了更有效地呈现文章内容,从而让读者更有针对性地选择阅读,通常会同时提供文章的标题和摘要. 一篇文章的内容可以是纯文本格式 ...
- Google地图接口API之地图类型(六)
1. Google 地图- 基本地图类型 Google Maps API 中提供了以下地图类型: MapTypeId.ROADMAP,用于显示默认的道路地图视图 MapTypeId.SATELLITE ...