HDU 1728:逃离迷宫(BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1728
逃离迷宫
第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对应行。
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <algorithm>
- using namespace std;
- #define N 105
- struct node
- {
- int x, y, dre, t;
- node () {}
- node (int x, int y, int dre, int t) : x(x), y(y), dre(dre), t(t) {}
- };
- char maze[N][N];
- bool vis[N][N][][];
- int dx[] = {, -, , }, dy[] = {, , , -};
- int sx, sy, ex, ey, k, n, m;
- bool check(int x, int y)
- {
- if(<=x&&x<m&&<=y&&y<n&&maze[x][y]!='*') return true;
- return false;
- }
- //&&!vis[x][y]
- /*
- 2
- 5 5
- .....
- .*.*.
- .....
- .*.*.
- .....
- 1 1 1 3 4
- */
- bool bfs()
- {
- queue<node> que;
- memset(vis , ,sizeof(vis));
- que.push(node(sx, sy, -, ));
- while(!que.empty()) {
- node u = que.front(); que.pop();
- if(u.x == ex && u.y == ey && u.t <= k) return true;
- if(u.t > k) continue;
- if(u.dre != -) {
- if(vis[u.x][u.y][u.dre][u.t]) continue;
- vis[u.x][u.y][u.dre][u.t] = ;
- }
- for(int i = ; i < ; i++) {
- int nx = u.x + dx[i], ny = u.y + dy[i];
- if(!check(nx, ny)) continue;
- if(u.dre == -) {
- que.push(node(nx, ny, i, u.t));
- continue;
- }
- que.push(node(nx, ny, i, u.dre == i ? u.t : u.t + ));
- }
- }
- return false;
- }
- int main()
- {
- int t;
- scanf("%d", &t);
- while(t--) {
- scanf("%d%d", &m, &n);
- for(int i = ; i < m; i++)
- scanf("%s", maze[i]);
- scanf("%d%d%d%d%d", &k, &sy, &sx, &ey, &ex);
- sy--, sx--, ey--, ex--;
- if(maze[sx][sy] == '*' || maze[ex][ey] == '*') {
- puts("no"); continue;
- }
- if(bfs()) puts("yes");
- else puts("no");
- }
- 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)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- 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 ...
随机推荐
- 知识准备-JOIN/EXISTS
10:40 2013-08-29 JOIN ON...AND A left join B on A.col1=B.col1 and A.col2=xx A left join B on A.col1= ...
- PLSQL 的简单命令之三
-- 查找两个表中ID相等的 select a.id, a.name,b.math from stu a,scores b where a.id = b.id -- 右外连接 select b.id, ...
- Springfox Reference Documentation
1. Introduction The Springfox suite of java libraries are all about automating the generation of mac ...
- 异常处理原则--good
异常机制是现代主流语言的标配,但是异常处理问题虽然已经被讨论很多,也有很多经典书籍的论述,却一直都充满争议.很多人都觉得异常处理很难拿捏,同时也难以理解一些语言或库的异常处理设计.我使用Java近10 ...
- JAVA线程基础
一.线程状态 由于参考的维度不一样,线程状态划分也不一样,我这里简单的分为5大类,并且会说明状态变迁的详细过程:
- PostgreSQL数据库中跨库访问解决方案
PostgreSQL跨库访问有3种方法:Schema,dblink,postgres_fdw. 方法A:在PG上建立不同SCHEMA,将数据和存储过程分别放到不同的schema上,经过权限管理后进行访 ...
- WebDriver 随笔
在webDriver中通过 driver.findElement进行定位元素时,往往是从页面的上到下依次寻找,根据该等位方式寻找到第一个元素. driver.findElement(By.id())有 ...
- struts自定义拦截器
第01步:配置web.xml,启动struts框架 <?xml version="1.0" encoding="UTF-8"?> <web-a ...
- haskell笔记1
haskell platform下载:https://www.haskell.org/platform/ 进入haskell控制台,终端输入 $ ghci 编译文件 :l file.hs 数组操作 & ...
- 针对Android 模拟器启动慢的问题
Android 模拟器一直以运行速度慢著称,可以使用intel HAXM技术为Andorid模拟器加速.使模拟器运行度媲美真机, 彻底解决模拟器运行慢的问题. 1. Intel HAXM 是什么 In ...