逃离迷宫 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可 ...
随机推荐
- docker mysql安装
Docker MySQL-Server 安装1.搜索docker search mysql# 一般会选择mysql-server 版本 2.拉取 docker pull mysql-server 3. ...
- MVC的viewPage 通用属性运用。
试想下在MVC的前端页面JS或者html中需要使用多语言,而后端的多语言是维护在资源文件中的,前端如果使用的话需要使用AJAX频繁的获取,一个页面中可能会存在大量的需要语言转换的地方,频繁使用AJAX ...
- 在前端解決顯示null值一例
用.net core2.1 api返回的JSON里包含null值,前端直接顯示出來了,影響閱讀, 用以下語句將null轉換為空字符串: // Build html. html += "< ...
- 关于报错“More than one fragment with the name [spring_web] was found. This is not legal ...”的解决办法
最近在搭建一个spring mvc 项目时遇到“More than one fragment with the name [spring_web] was found. This is not leg ...
- Ubuntu获取root 权限,开机自动登入root
新机器获取root权限,只需要给root 增加密码: sudo passwd root 修改开机自动登入: #sudo gedit /etc/lightdm/lightdm.conf 修改参数: au ...
- mac不限速下载百度网盘
本文转载自:https://blog.csdn.net/u010837612/article/details/80029212 相信大家都比较困惑,百度网盘客户端限速后一般只有几十K的下载速度,Win ...
- javaSe-hashMap
package com.java.chap08.sec05; public class Student { private String name; private Integer age; publ ...
- Windows 7, Visual Studio 2015下编译Webkit
因工作需要,需要编译Windows版本的Webkit,中间走了不少弯路,都记录下来,供大家参考!也随时欢迎大家讨论(QQ群:345802342) 整个编译工作参考的是官方文档:https://webk ...
- IE浏览器已经卸载,但是桌面上的图标却无法删除的解决方案
第一步——win+R运行[regedit],打开注册表. 第二步——在注册表里面依次找到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVer ...
- Android系统Binder机制学习总结
一.Binder机制概述 在Android开发中,很多时候我们需要用到进程间通信,所谓进程间通信,实现进程间通信的机制有很多种,比如说socket.pipe等,Android中进程间通信的方式主要有三 ...