简单bfs,记录好状态即可

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt,k;
int dir[][]={,,-,,,,,-};
char s[MAXN][MAXN];
struct Node
{
int x,y;
int st;
int t;
}node[MAXN],st,ed;
bool vis[MAXN][MAXN][][];
bool bfs()
{
queue<Node> q;
cl(vis);
Node now,next;
st.t=;
st.st=;
vis[st.x][st.y][st.st][st.t]=;
q.push(st);
st.st=;
vis[st.x][st.y][st.st][st.t]=;
q.push(st);
st.st=;
vis[st.x][st.y][st.st][st.t]=;
q.push(st);
st.st=;
vis[st.x][st.y][st.st][st.t]=;
q.push(st);
while(!q.empty())
{
now=q.front();
q.pop();
if(now.x==ed.x&&now.y==ed.y)
{
return ;
}
for(int i=;i<;i++)
{
next.x=now.x+dir[i][];
next.y=now.y+dir[i][];
next.t=now.t;
next.st=i;
if(i!=now.st) next.t+=,next.st=i;
if(next.x>=&&next.x<n&&next.y>=&&next.y<m&&!vis[next.x][next.y][i][next.t]&&s[next.x][next.y]!='*'&&next.t<=k)
{
if(now.st==i)
{
q.push(next);
vis[next.x][next.y][i][next.t]=;
}
else
{
q.push(next);
vis[next.x][next.y][i][next.t]=;
}
}
}
}
return ;
}
int main()
{
int i,j;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%s",&s[i]);
}
scanf("%d%d%d%d%d",&k,&st.y,&st.x,&ed.y,&ed.x);
st.x-=;
st.y-=;
ed.x-=;
ed.y-=;
if(bfs())
{
printf("yes\n");
}
else printf("no\n");
}
}

hdu 1728 bfs **的更多相关文章

  1. 逃离迷宫(HDU 1728 BFS)

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

  2. HDU 1728 逃离迷宫

    [题目描述 - Problem Description] 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,glo ...

  3. hdu 1728

    //hdu 1728 //这个是一道很经典的迷宫题了,思路感觉...取起点和终点,判断连线是否超过n个弯, //先是从起点出发,上下左右四个方向搜索,找到一条路,把那条路的第一个点压入队列 //然后沿 ...

  4. hdu 4531 bfs(略难)

    题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...

  5. HDU 1728:逃离迷宫(BFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Problem Description   给定一个m × n (m行, n列)的迷宫,迷宫中有 ...

  6. hdu - 1728逃离迷宫 && hdu - 1175 连连看 (普通bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1728 这两道题花了一下午的时候调试,因为以前做过类似的题,但是判断方向的方法是错的,一直没发现啊,真无语. 每个 ...

  7. hdu 1728 逃离迷宫 bfs记转向

    题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Mem ...

  8. HDU - 1728 逃离迷宫 【BFS】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1728 思路 BFS 一开始 从开始位置 往四周走 如果能走的话 这个时候 转弯次数都是0 我们的标记不 ...

  9. hdu 1728 逃离迷宫 bfs记步数

    题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Mem ...

随机推荐

  1. PHP文件包含漏洞剖析

    一. 什么才是”远程文件包含漏洞”?回答是:服务器通过php的特性(函数)去包含任意文件时,由于要包含的这个文件来源过滤不严,从而可以去包含一个恶意文件,而我们可以构造这个恶意文件来达到邪恶的目的. ...

  2. Center os FTP配置

    原文:http://www.aicoffees.com/itshare/412261137.html

  3. ExtJS学习之路第一步:对比jQuery,认识ExtJS

    最近纷杂的事情比较多了,奔波ing!所以,Node.js 和Canvas动画系列都停止了,等稳定了再重拾书本继续学习!因为某种原因最近在看ExtJS,分享下学习的心得,希望对同道中人有所帮助. 第一用 ...

  4. 繁华模拟赛 Vicent与游戏

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...

  5. 简单聊下IO复用

    没图,不分析API Java中IO API的发展:Socket -> SocketChannel -> AsynchronousSocketChannelServerSocket -> ...

  6. SpringMVC关于json、xml自动转换的原理研究

    SpringMVC是目前主流的Web MVC框架之一. 如果有同学对它不熟悉,那么请参考它的入门blog:http://www.cnblogs.com/fangjian0423/p/springMVC ...

  7. java笔记--超级类Object多线程的应用+哲学家进餐算法内部类与多线程结合

    关于Object类中的线程方法: Object类是所有Java类的 父类,在该类中定义了三个与线程操作有关的方法,使得所有的Java类在创建之后就支持多线程 这三个方法是:notify(),notif ...

  8. JS获取汉字首字母

    //获取 汉字首字母 function makePy(str) { if (typeof (str) != "string") throw new Error(-1, " ...

  9. [Effective JavaScript 笔记]第42条:避免使用轻率的猴子补丁

    41条对违反抽象原则行为的讨论之后,下面聊一聊终极违例.由于对象共享原型,因此每一个对象都可以增加.删除或修改原型的属性.这个有争议的实践通常称为猴子补丁. 猴子补丁示例 猴子补丁的吸引力在于其强大. ...

  10. Minimum Depth of Binary Tree

    二叉树的最小深度 采用递归的方式求左右结点的高度,注意判断一个结点是否是叶子结点(左右子树都不存大). int minDepth(TreeNode *root) { return minDepth(r ...