hdu 1728 逃离迷宫 (BFS)
逃离迷宫
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 44 Accepted Submission(s) : 23
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
第1行为两个整数m, n (1 ≤ m, n ≤ 100),分别表示迷宫的行数和列数,接下来m行,每行包括n个字符,其中字符'.'表示该位置为空地,字符'*'表示该位置为障碍,输入数据中只有这两种字符,每组测试数据的最后一行为5个整数k, x1, y1, x2, y2 (1 ≤ k ≤ 10, 1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m),其中k表示gloria最多能转的弯数,(x1, y1), (x2, y2)表示两个位置,其中x1,x2对应列,y1, y2对应行。
Output
Sample Input
2
5 5
...**
*.**.
.....
.....
*....
1 1 1 1 3
5 5
...**
*.**.
.....
.....
*....
2 1 1 1 3
Sample Output
no
yes
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,m,sx,sy,tx,ty,i,k,t;
char mp[][];
int vis[][];
int dr[][]={{,},{,},{-,},{,-} };
struct node
{
int x,y,k;
}; int check(int x,int y)
{
if (x>= && x<n && y>= && y<m) return ;
else return ;
}
int bfs()
{
node p;
queue<node> s;
p.x=sx;
p.y=sy;
p.k=-;
s.push(p);
vis[sx][sy]=;
while(!s.empty())
{
node q=s.front();
s.pop();
for(int i=;i<;i++)
{
int xx=q.x+dr[i][];
int yy=q.y+dr[i][];
while(mp[xx][yy]!='*' && check(xx,yy))
{
p.x=xx;
p.y=yy;
p.k=q.k+;
if (!vis[xx][yy])
{
s.push(p);
vis[xx][yy]=;
}
if (xx==tx && yy==ty)
if (p.k<=k)return ;
else return ;
xx=xx+dr[i][];
yy=yy+dr[i][]; }
}
}
return ;
}
int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%s",&mp[i]);
scanf("%d%d%d%d%d",&k,&sy,&sx,&ty,&tx);
sy--; sx--; ty--; tx--;
memset(vis,,sizeof(vis));
if(bfs())printf("yes\n");
else printf("no\n");
}
return ;
}
hdu 1728 逃离迷宫 (BFS)的更多相关文章
- 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 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- hdu 1728 逃离迷宫 BFS加优先队列 DFS()
http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意就是能否在规定的转弯次数内从起点走到终点.刚走时那步方向不算. 只会bfs(),但想到这题需要记录转弯 ...
- HDU 1728 逃离迷宫 BFS题
题目描述:输入一个m*n的地图,地图上有两种点,一种是 . 表示这个点是空地,是可以走的,另一种是 * ,表示是墙,是不能走的,然后输入一个起点和一个终点,另外有一个k输入,现在要你确定能否在转k次弯 ...
- HDU 1728 逃离迷宫(DFS||BFS)
逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
- HDU 1728 逃离迷宫(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题目: 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) ...
- HDU 1728 逃离迷宫
[题目描述 - Problem Description] 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,glo ...
- HDU 1728 逃离迷宫(DFS经典题,比赛手残写废题)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 1728:逃离迷宫(DFS,剪枝)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- LeetCode OJ 78. Subsets
Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...
- 解决MOSS列表匿名访问问题
//匿名 http://blog.csdn.net/yang_5/article/details/5214293 这是发布以后MOSS网站,如果你一开始在内部都没有启用匿名访问,你设置这个是不启作用 ...
- linux双线ip设置(不需额外增加路由表)
linux 双线ip设置(不需额外增加路由表,只需修改下面就ok了)修改 vi /etc/iproute2/rt_tables (增加电信和网通两个路由表) 增加252 ...
- sql标识符和格式
数据库名是一个标识符,表名也是一个标识符,在SQL SERVER中标识符分为两类: (1).常规标识符;(2).分隔标识符两者重要的区别:常规标识符必须严格遵守命名的规定,而分隔标识符则可以不遵守命名 ...
- HDU1115--Lifting the Stone(求凸多边形的重心)
Problem Description There are many secret openings in the floor which are covered by a big heavy sto ...
- Access to the path "Library\UnityAssemblies\UnityEngine.xml" is denied.
这个问题基本上是重新打开UnityEditor,导入工程的时候VisualStudio还开着导致的. 解决方法是关掉Visual Studio,再重新打开.
- Ubuntu cron定时执行任务
1.添加自定义事件 crontab -e 2.选定编辑器 3.添加执行代码 * * * * /usr/bin/curl http://www.exmple.com/cron.php crontab 命 ...
- position:fixed 居中问题
设置Css属性position:fixed后如何使这个盒子居中呢?其实也很简单: 就是需要设置给这个div盒子设置属性: left:0; right:0; margin:0 auto; ******* ...
- JavaScript中以构造函数的方式调用函数
转自:http://www.cnblogs.com/Saints/p/6012188.html 构造器函数(Constructor functions)的定义和任何其它函数一样,我们可以使用函数声明. ...
- 【读书笔记】Linux源码注释
第二章 大概的内部组成 IO端口寻址: 统一寻址: 就是把地址归入存储器寻址范围. 独立寻址: 跟存储器分开,专门的寻址空间 没怎么理解, PC机一般都是采用独立寻址, 见下图 在linux里,可以在 ...