逃离迷宫

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34147    Accepted Submission(s): 8333

Problem Description
  给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的。我们假定给定的两个位置都是空地,初始时,gloria所面向的方向未定,她可以选择4个方向的任何一个出发,而不算成一次转弯。gloria能从一个位置走到另外一个位置吗?
 
Input
  第1行为一个整数t (1 ≤ t ≤ 100),表示测试数据的个数,接下来为t组测试数据,每组测试数据中,
  第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
  每组测试数据对应为一行,若gloria能从一个位置走到另外一个位置,输出“yes”,否则输出“no”。
 

Sample Input

2
5 5
...**
*.**.
.....
.....
*....
1 1 1 1 3
5 5
...**
*.**.
.....
.....
*....
2 1 1 1 3

Sample Output

no
yes
 
题意:逃离迷宫,转弯的次数要小于题目给的最大转弯数
思路:bfs,能往前走就往前走,输入行和列的时候看清楚啊,呜呜呜呜
 
#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)的更多相关文章

  1. 逃离迷宫(HDU 1728 BFS)

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

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

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

  3. hdu 1728 bfs **

    简单bfs,记录好状态即可 #include<cstdio> #include<iostream> #include<algorithm> #include< ...

  4. 逃离迷宫 HDU1728 (bfs)

    和连连看非常相似   都是求转向的BFS 改了一下就上交了... #include<cstdio> #include<cstring> #include<algorith ...

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

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

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

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

  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)

    逃离迷宫 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  9. HDU 1728 逃离迷宫(DFS||BFS)

    逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...

随机推荐

  1. 学习 primer 第8章 IO库 小结

    iostream处理控制台IO fstream处理命名文件IO stringstream完成内存string的IO 非常重要!!!!!!!!!!  ========================== ...

  2. 1.7hashmap并发成环

    https://mp.weixin.qq.com/s?__biz=MzIxMjE5MTE1Nw==&mid=2653192000&idx=1&sn=118cee6d1c67e7 ...

  3. 开园了,将以此记录个人web前端之路

    记录.分享与学习 2015年5月中旬开始学习web前端到2015年6月底找到第一份相关工作,在学习与工作过程中通过网络获益良多,在此写下个人学习与工作过程中的总结与思考,记录个人成长,同时也希望能够帮 ...

  4. CSS grid layout demo 网格布局实例

    直接 上代码,里面我加注释,相当的简单, 也可以去我的github上直接下载代码,顺手给个星:https://github.com/yurizhang/micro-finance-admin-syst ...

  5. 介绍我最近做的网站 Asp.Net MVC4 + BootStrap

    一.前言 最近一直在做一个多站SEO数据分析的站点(www.easyyh.com),用了一些新技术,如Asp.Net MVC4,BootStrap,EasyUI,这些都是以前没有搞过的,最近搞得差不多 ...

  6. If people in the communications only think about gains and losses of interest, then the pleasure of knowing each other will cease to exist.

    If people in the communications only think about gains and losses of interest, then the pleasure of ...

  7. ubuntu下irobot串口通讯

    在window下以前就`有一个现成的串口代码.想移植到ubuntu下,发现都不一样了.要重新找个. 折腾了一上午之后,发现自己写这个串口通讯还是有一点难度. 于是,用了github上 Erick Co ...

  8. A winner is a dreamer who never gives up

    A winner is a dreamer who never gives up. 成功者是坚持梦想不放弃的人.(Nelson Mandela)

  9. BFS 简单思想以及代码

    BFS(广搜思想) 广度优先搜索 广度优先搜索是图论的搜索算法之一,以下便进行简单叙述 对于每一个顶点来说,都存在着三种颜色 白色,灰色,黑色 而对于每个顶点,都有三种数据类型 颜色类型,前驱或者父节 ...

  10. cityspace

    类别的网址:https://blog.csdn.net/u010069760/article/details/77847595 r,g,b:  250 170 160 parking   244 35 ...