hdu 1728 bfs **
简单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 **的更多相关文章
- 逃离迷宫(HDU 1728 BFS)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1728 逃离迷宫
[题目描述 - Problem Description] 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,glo ...
- hdu 1728
//hdu 1728 //这个是一道很经典的迷宫题了,思路感觉...取起点和终点,判断连线是否超过n个弯, //先是从起点出发,上下左右四个方向搜索,找到一条路,把那条路的第一个点压入队列 //然后沿 ...
- hdu 4531 bfs(略难)
题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...
- HDU 1728:逃离迷宫(BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有 ...
- hdu - 1728逃离迷宫 && hdu - 1175 连连看 (普通bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 这两道题花了一下午的时候调试,因为以前做过类似的题,但是判断方向的方法是错的,一直没发现啊,真无语. 每个 ...
- hdu 1728 逃离迷宫 bfs记转向
题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- HDU - 1728 逃离迷宫 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1728 思路 BFS 一开始 从开始位置 往四周走 如果能走的话 这个时候 转弯次数都是0 我们的标记不 ...
- hdu 1728 逃离迷宫 bfs记步数
题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Mem ...
随机推荐
- 锋利的jQuery-7--一个$.fn.color插件的编写过程
编写一个设置和获取元素的color的插件: 首先实现第一个功能,设置: ;(function($){ $.fn.extend({ color:function(value){ return this. ...
- php排序 sort、rsort、asort、arsort、ksort、krsort
sort() 函数用于对数组单元从低到高进行排序. rsort() 函数用于对数组单元从高到低进行排序. asort() 函数用于对数组单元从低到高进行排序并保持索引关系. arsort() 函数用于 ...
- asp.net记住我功能
登录页面的记住我功能 不能用session的原因:sessionID是以cookie的形式存在浏览器端的内存中 如果用户把浏览器关闭 则sessionID就消失 但是服务器端的sessi ...
- Linux(Ubuntu)下面SecureCRT 完全破解
转载声明:本文来自http://www.boll.me/archives/680 相关说明: 上篇发了个Linux(Ubuntu) 下 SecureCRT 7 30天循环破解在启动的时候会多输入一次确 ...
- CSS 定义上划线、下划线、删除线代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Open Credit System
Open Credit SystemInput: Standard Input Output: Standard Output In an open credit system, the studen ...
- HDU 1062 Text Reverse(水题,字符串处理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include< ...
- Centos7上使用官方YUM源安装Mysql
1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. 安装mysql-co ...
- 《第一行代码》(三: Android 百度地图 SDK v3.0.0)
百度地图的SDK变化较大,第一行代码里的demo已经不能用了,一直以为是代码类错误,害我花了很多时间,可以参考这位博主的:http://blog.csdn.net/lmj623565791/artic ...
- facedetect
继续学习大神的博文http://www.cnblogs.com/tornadomeet/archive/2012/03/22/2411318.html