是一个图论的基础搜索题~

没什么好说的就是搜索就好 主要是别把 代码写的太屎,错了不好找

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int sx,sy,ex,ey;
struct info
{
int x,y;
char ko;
int qian;
};
info que[40];
bool flag[10][10];
int n,m;
bool vi[10][10][4];
int d[4][2]={-1,0,1,0, 0,-1, 0, 1};
char dd[5]={"WENS"};
void print(int p)
{
if(p!=0) print(que[p].qian);
if(p!=0)printf("%c",que[p].ko);
}
bool jude(int x,int y)
{
return x>=1&&y>=1&&x<=6&&y<=6&&flag[x][y]==0;
}
void solve()
{
int h=0,r=1;
int x,y,x0,y0;
que[0].x=sx,que[0].y=sy;
flag[sx][sy]=1;
while(h!=r)
{
x=que[h].x;
y=que[h].y;
h++;
for(int i=0;i<4;i++)
{
if(vi[x][y][i])
{
x0=x+d[i][0];
y0=y+d[i][1];
if(jude(x0,y0))
{
flag[x0][y0]=1;
que[r].x=x0;
que[r].y=y0;
que[r].qian=h-1;
que[r].ko=dd[i];
if(x0==ex&&y0==ey) {print(r);return ;}
r++;
}
}
}
}
}
int main()
{
int a,b,c,d;
while(~scanf("%d%d",&sx,&sy))
{
if(sx==0&&sy==0) break;
memset(vi,1,sizeof(vi));
memset(flag,0,sizeof(flag));
scanf("%d%d",&ex,&ey);
for(int i=0;i<3;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a==c)
{
for(int i=min(b,d)+1;i<=max(b,d);i++)
vi[a][i][1]=0,vi[a+1][i][0]=0;
}
else if(b==d)
{
for(int i=min(a,c)+1;i<=max(a,c);i++)
vi[i][b][3]=0,vi[i][b+1][2]=0;
}
}
solve();printf("\n");
}
return 0;
}

  

poj 2935 Basic Wall Maze的更多相关文章

  1. HDU 1484 Basic wall maze (dfs + 记忆)

    Basic wall maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. poj-2935 BFS Basic Wall Maze

    Basic Wall Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3384   Accepted: 1525   ...

  3. Basic Wall Maze

    poj2935:http://poj.org/problem?id=2935 题意:在6*6的格子中,有一些,如果两个格子之间有墙的话,就不能直接相通,问最少要经过几步才能从起点走到终点.并且输出路径 ...

  4. 【HDOJ】1484 Basic wall maze

    BFS. /* 1484 */ #include <iostream> #include <queue> #include <string> #include &l ...

  5. 【POJ 3026】Borg Maze

    id=3026">[POJ 3026]Borg Maze 一个考察队搜索alien 这个考察队能够无限切割 问搜索到全部alien所须要的总步数 即求一个无向图 包括全部的点而且总权值 ...

  6. POJ 3026 : Borg Maze(BFS + Prim)

    http://poj.org/problem?id=3026 Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. (POJ 3026) Borg Maze 最小生成树+bfs

    题目链接:http://poj.org/problem?id=3026. Description The Borg is an immensely powerful race of enhanced ...

  8. 【POJ】1113 Wall(凸包)

    http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...

  9. POJ 1113:Wall(凸包)

    http://poj.org/problem?id=1113 Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 346 ...

随机推荐

  1. 不起眼的 z-index 却能牵扯出这么大的学问(转)

    z-index在日常开发中算是一个比较常用的样式,一般理解就是设置标签在z轴先后顺序,z-index值大的显示在最前面,小的则会被遮挡,是的,z-index的实际作用就是这样. 但是你真的了解z-in ...

  2. OCA读书笔记(14) - 备份和恢复基本概念

    备份恢复概念 如何判断数据库的一致性 在mount状态下,oracle如何判断数据库的一致性 scn:system change number,它是数据库时钟 如何查询当前系统的scn: select ...

  3. git配置流程

    写的比较简略,主要是记录一下,以后配置别的机器的时候看一下,仅供参考. 1 安装 命令依赖包 sudo apt-get install git-core git-gui git-doc 2 设置SSH ...

  4. python实用小代码

    栈的实现 #!/usr/bin/env python #coding=utf-8 #python version 2.7.4 class stack: def __init__(self,list=N ...

  5. Android的PackageManager的使用

    Android系统提供了很多服务管理的类,包括ActivityManager.PowerManager(电源管理).AudioManager(音频管理)以及PackageManager管理类.Pack ...

  6. STL源代码剖析 容器 stl_hashtable.h

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie hashtable ------------------------------------ ...

  7. mysql5.1,5.5,5.6做partition时支持的函数

    mysql5.1支持的partition函数(http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations-functions.htm ...

  8. css中换行的几种方式

    1.white-space:normal;   这个只针对中文有效 2.word-break:break-all;  强制换行,针对中文,数字,英文等都有效: 3.word-wrap:break-wo ...

  9. mysql表修改

    CREATE TABLE tab2 AS (SELECT * FROM tab1)这种做法表的存储引擎也会采用服务器默认的存储引擎而不是源表的存储引擎,此种复制方法把表的内容也一起复制过来了. CRE ...

  10. ecshop首页调用某分类下的商品|assign_cat_goods()

    ecshop首页调用分类下的商品其实很简单,也有模板设置那里可以设置,不过那个只可以用cat_goods.lib,不方便,所以我想看看怎么能简单的实现ecshop首页调用分类下的商品 只需要在inde ...