逃离迷宫 HDU - 1728(bfs)
逃离迷宫
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34147 Accepted Submission(s): 8333
第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对应行。
Sample Input
2
5 5
...**
*.**.
.....
.....
*....
1 1 1 1 3
5 5
...**
*.**.
.....
.....
*....
2 1 1 1 3
Sample Output
no
yes
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=; int n,m;
int max_turn;
int start_x,start_y,end_x,end_y;
char a[maxn][maxn];
bool vis[maxn][maxn];
int dir[][]={,,,,,-,-,}; struct node
{
int x,y;
int turn_num;
}; int bfs()
{
queue<node>que;
node q1;
q1.x=start_x;
q1.y=start_y;
q1.turn_num=-;
que.push(q1);
vis[start_x][start_y]=;
while(!que.empty())
{
node q2=que.front();
que.pop();
if(q2.x==end_x && q2.y==end_y && q2.turn_num<=max_turn)
return ;
q1.turn_num=q2.turn_num+;
for(int i=;i<;i++)
{
q1.x=q2.x+dir[i][];
q1.y=q2.y+dir[i][];
while(q1.x>= && q1.x<=n && q1.y>= && q1.y<=m && a[q1.x][q1.y]=='.' )
{
if(!vis[q1.x][q1.y])
{
que.push(q1);
vis[q1.x][q1.y]=;
}
q1.x=q1.x+dir[i][];
q1.y=q1.y+dir[i][];
}
} }
return ;
} int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
cin>>a[i][j];
cin>>max_turn>>start_y>>start_x>>end_y>>end_x;
memset(vis,,sizeof(vis));
if(bfs())
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return ;
}
逃离迷宫 HDU - 1728(bfs)的更多相关文章
- 逃离迷宫(HDU 1728 BFS)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu - 1728逃离迷宫 && hdu - 1175 连连看 (普通bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 这两道题花了一下午的时候调试,因为以前做过类似的题,但是判断方向的方法是错的,一直没发现啊,真无语. 每个 ...
- hdu 1728 bfs **
简单bfs,记录好状态即可 #include<cstdio> #include<iostream> #include<algorithm> #include< ...
- 逃离迷宫 HDU1728 (bfs)
和连连看非常相似 都是求转向的BFS 改了一下就上交了... #include<cstdio> #include<cstring> #include<algorith ...
- HDU 1728:逃离迷宫(BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有 ...
- 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)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- HDU 1728 逃离迷宫(DFS||BFS)
逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
随机推荐
- net Core 2.0应用程序发布到IIS
.net Core 2.0应用程序发布到IIS上注意事项 .net Core2.0应用程序发布window服务器报错容易错过的配置. 1.应用程序发布. 2.IIS上新建网站. 3.应用程序池选择 ...
- Nuxt使用记录
代码及插件需要根据环境引入 (服务端没有window,document,浏览器端没有global) const myPlugins = { install(Vue, options) { Vue.pr ...
- swift基础-2
一.基本运算符 let a = 5 var b = 10 b = a if a = b{ swift 中赋值运算符,并不将自身作为一个值进行返回,所以编译不合法,帮开发者避免错误,很人性化的语言 } ...
- 织梦后台上传mp4视频不显示
include/dialog/select_media.php ,约185行, 把(rm|rmvb) 改为(rm|mp4|rmvb)
- 验证fgets末尾自动添加的字符是'\0' 还是 '\n\'?
最近写代码经常使用字符串,对于输入函数fgets网上有人说输入结束会在末尾自动添加'\n',还有人说添加的是'\n',我决定亲自验证: #include "iostream" #i ...
- Beginning Python Chapter 3 Notes
变量(variable)是储存数据的实体,在Python中也被称为"名称"(name). 1.Python"名称"基本命名法则 1.1) "名称&qu ...
- Microsoft Exchange本地和Exchange Online可以与第三方服务共享
很多人都知道Office 365中的Microsoft Exchange本地和Exchange Online可以与第三方服务共享您的个人数据?例如,在Exchange电子邮件中找到的任何地图地址都会发 ...
- LINQ 组合查询 和分页查询的使用
前端代码 <%@ Page Language="C#" AutoEventWireup="true" Debug="true" Cod ...
- JDBC + SAP云平台 = 运行在云端的数据库应用
在前一篇文章JPA + EclipseLink + SAP云平台 = 运行在云端的数据库应用我介绍了如何通过JPA和EclipseLink操作部署在SAP云平台上的HANA数据库实例. 在这篇文章里, ...
- 学习Unity 4.6新GUI系统
(搬运自我在SegmentFault的博客) 最近在学习Unity的过程中,自己做一款小游戏自娱自乐.自然需要用到GUI.但4.5中的GUI很难用,一个选择是传说中的NGUI插件.但对于4.6中的新G ...