#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的更多相关文章

  1. ZOJ 1649 Rescue(有敌人迷宫BFS)

    题意 求迷宫中从a的位置到r的位置须要的最少时间  经过'.'方格须要1s  经过'x'方格须要两秒  '#'表示墙 因为有1s和2s两种情况  须要在基础迷宫bfs上加些推断 令到达每一个点的时间初 ...

  2. bfs—迷宫问题—poj3984

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20591   Accepted: 12050 http://poj ...

  3. 迷宫问题---poj3984(bfs,输出路径问题)

    题目链接 主要就是输出路径问题: pre[x][y]表示到达(x,y)是由点(pre[x][y].x,  pre[x][y].y)而来: #include<stdio.h> #includ ...

  4. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  5. 暑假集训(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, ...

  6. poj 1383 Labyrinth【迷宫bfs+树的直径】

    Labyrinth Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 4004   Accepted: 1504 Descrip ...

  7. hdu_1728_逃离迷宫(bfs)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意:走迷宫,找最小的拐角 题解:对BFS有了新的理解,DFS+剪枝应该也能过,用BFS就要以拐 ...

  8. hdu 1728 逃离迷宫 (BFS)

    逃离迷宫 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  9. HDU1728-逃离迷宫-BFS

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. hdu 1754 单点更新

    题意:很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师 ...

  2. 继承ActionSupport,返回INPUT的原因

    http://developer.51cto.com/art/200907/134757.htm 表面现象: 在WebWork中,当一个Action中既没有重写ActionSupport中的valid ...

  3. Android判断App是否在前台运行(转)

    原文地址: http://blog.csdn.net/zuolongsnail/article/details/8168689 Android开发中,有时候需要判断App是否在前台运行. 代码实现如下 ...

  4. c# 作业1

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 【HTML5】Video + DOM

    效果图: <!DOCTYPE html> <html> <body> <div style="text-align:center;"> ...

  6. javascript优化--05模式(函数)

    回调函数模式: 基本例子: var findNodes = function (callback) { ...................... if (typeof callback !== ' ...

  7. [LintCode] Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  8. 游戏 gui button

    using UnityEngine; using System.Collections; public class Gui : MonoBehaviour { public Texture2D but ...

  9. BZOJ3808 : Neerc2012 Labyrinth of the Minotaur

    左上角和右下角不四连通等价于左下角和右上角八连通 枚举正方形的左上角,先二分出最大的边长,使得里面不含障碍物 然后再二分出最小的边长,使得两部分连通,用前缀和判断 这题WA了好久…一直对拍都没问题…于 ...

  10. MathType 插入定义的chapter and section break后无法隐藏

    每一章标题后面插入一个“Next Section Break”,这样定稿后各章文件组合为总文件后,方程编号会自动递增,如果已经插入了默认的“Equation Chapter 1 Section 1”, ...