【HDOJ】1728 逃离迷宫
题目大坑,注意行列顺序式反的,另外注意起点和终点相同。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; #define MAXN 105 typedef struct node_st {
int x, y, d;
int t;
node_st(){}
node_st(int xx, int yy, int dd, int tt) {
x = xx; y = yy; d = dd; t = tt;
}
} node_st; char map[MAXN][MAXN];
char turns[MAXN][MAXN];
int direct[][]={-,,,,,-,,};
int n, m, maxt; int bfs(int x, int y, int ex, int ey) {
int i, j, t;
queue<node_st> que;
node_st node;
memset(turns, 0x3f, sizeof(turns));
map[x][y] = '*';
que.push(node_st(x,y,,)); while ( !que.empty() ) {
node = que.front();
que.pop();
for (i=; i<; ++i) {
x = node.x + direct[i][];
y = node.y + direct[i][];
if (x< || x>=n || y< || y>=m || map[x][y]=='*')
continue;
if (i == node.d)
t = node.t;
else
t = node.t+;
if (t > maxt+)
continue;
if (x==ex && y==ey)
return ;
if (t <= turns[x][y]) {
que.push(node_st(x,y,i,t));
turns[x][y] = t;
}
}
} return ;
} int main() {
int case_n, bx, by, ex, ey;
int i; scanf("%d", &case_n); while (case_n--) {
scanf("%d %d", &n, &m);
for (i=; i<n; ++i)
scanf("%s", map[i]);
scanf("%d%d%d%d%d",&maxt,&by,&bx,&ey,&ex);
if (bx==ex && by==ey) {
printf("yes\n");
continue;
}
i = bfs(bx-,by-,ex-,ey-);
if (i)
printf("yes\n");
else
printf("no\n");
} return ;
}
【HDOJ】1728 逃离迷宫的更多相关文章
- BFS HDOJ 1728 逃离迷宫
题目传送门 /* BFS:三维BFS,加上方向.用dp[x][y][d]记录当前需要的最少转向数 */ #include <cstdio> #include <algorithm&g ...
- hdoj 1728 逃离迷宫
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 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 逃离迷宫(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题目: 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) ...
- 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 Su ...
- hdu 1728:逃离迷宫(DFS,剪枝)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1728 逃离迷宫(DFS||BFS)
逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
- hdu 1728 逃离迷宫 (BFS)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
随机推荐
- angularjs ng-repeat checkbox
<div class="col-md-3" ng-repeat="user in title.UserList"> <p class=&quo ...
- System Operations on AWS - Lab 7 - CloudFormation
CloudFormation模板:创建一个VPC(包含Public子网,Private子网,分别在不同的AZ),创建NAT,Bastion Server在Public子网. 1. 修改并运行AWS C ...
- jquery判断浏览器版本插件,jquery-browser.js
jquery判断浏览器版本插件,jquery-browser.js,jquery 判断是否为ie浏览器插件 >>>>>>>>>>>&g ...
- [DEncrypt] HashEncode--哈希加密帮助类 (转载)
点击下载 HashEncode.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.HashEncode 得到随机哈希加密字符串2.HashEncode 得到一个随机数值3.HashEncod ...
- 获取SqlServer当前链接数
1.提供有关 Microsoft SQL Server 数据库引擎实例中的当前用户.会话和进程的信息,显示所有session sp_who 2.针对 SQL Server 上的每个经过身份验证的会话返 ...
- MyEclipse激活失败,解决办法
文章参考:http://www.cnblogs.com/dingyuanxin/p/4046356.html 失败可能是:systemid和exe破解出来的那个对应不上: 1.启动MyEclipse, ...
- 关于基于.net的WEB程序开发所需要的一些技术归纳
前提: 最近公司里有一个同事,年龄比我大几岁,但是由于是转行来做开发的,许多的关于.net开发技术不是很入行,所以总是会问我一些东西,基于自己以前的一些 经验,总是会愿意给他讲一些总结性的东西,希望他 ...
- Quartz-2D绘图之路径(Paths)详解
在上篇文章中,我们简单的理解了绘图上下文,今天我们来认识一下Quartz-2D中另一个重要的概念,路径(Paths). 一.理解路径 路径定义了一个或多个形状,或是子路径.一个子路径可由直线,曲线,或 ...
- CSS3弹性盒模型flex box快速入门 2016.03.16
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 深入理解JAVA多态原理
之前一直知道多态是什么东西,平时敲代码也经常用到多态,但一直没有真正了解多态底层的运行机制到底是怎么样的,这两天才研究明白点,特地写下来,跟各位同学一起进步,同时也希望各位大神指导和指正. 多态的概念 ...