题目大坑,注意行列顺序式反的,另外注意起点和终点相同。

 #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 逃离迷宫的更多相关文章

  1. BFS HDOJ 1728 逃离迷宫

    题目传送门 /* BFS:三维BFS,加上方向.用dp[x][y][d]记录当前需要的最少转向数 */ #include <cstdio> #include <algorithm&g ...

  2. hdoj 1728 逃离迷宫

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

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

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

  4. hdu 1728 逃离迷宫 bfs记步数

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

  5. HDU 1728 逃离迷宫(DFS)

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

  6. HDU 1728 逃离迷宫(DFS经典题,比赛手残写废题)

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

  7. hdu 1728 逃离迷宫 [ dfs ]

    传送门 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. hdu 1728:逃离迷宫(DFS,剪枝)

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

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

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

  10. hdu 1728 逃离迷宫 (BFS)

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

随机推荐

  1. Spring声明式事务(xml配置事务方式)

    Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...

  2. CSS background-position随笔

    1.定义和用法 background-position 属性设置背景图像的起始位置. 这个属性设置背景原图像(由 background-image 定义)的位置,背景图像如果要重复,将从这一点开始. ...

  3. TransactionScope简单用法

    记录TransactionScope简单用法,示例如下: void Test() { using (TransactionScope scope = new TransactionScope()) { ...

  4. SqlSugar常用查询实例-拉姆达表达式

    SqlSugar支持拉姆达表达式查询,匿名对象参数等,相对还是比较方便好用的. 一.查询列表: //查询列表 SqlSugarClient db = SugarContext.GetInstance( ...

  5. 在fragment中调用SharedPreferences

    [o] Activity中调用SharedPreferences的方式: String prefsName = "mysetting"; SharedPreferences pre ...

  6. Windows Azure 试用 for 世纪互联运维

    前一段时间申请由世纪互联运维的和谐版Windows Azure的邀请嘛下来,今天花费了点时间注册了一下 注册邀请函, 根据提示输入邀请码之后会收到以下邮件 中国地区可选择建立的虚拟机,SQL Serv ...

  7. hibernate逆向工程生成的实体映射需要修改

    根据实际情况进行修改,主要2处,注释的位置<!-- 把catalog="platform"删掉 -->,<!-- 替换为native -->   <? ...

  8. Oracle学习【索引及触发器】

    索引B_Tree结构 请参照 响应图例 索引是一种允许直接访问数据表中某一数据行的树形结构,为了提高查询效率而引入,是独立于表的对象,可以存放在与表不同的表空间中.索引记录中存有索引关键字和指向表中数 ...

  9. QVW中实现日期区间的选择功能!

    QV在日期的选择上不是很灵活,日期区段的选择可以在列表框中直接用鼠标拖拉区段,如果跨周期比较长了还是不是很方便啦. 下面介绍的方式是完全实现了起始日期的选择功能. 注:日期这个字段在抽取的时候一定要格 ...

  10. OC基础-day02

    #pragma mark - Day02_01_对象的创建与使用 1)如何通过类创建一个对象 1. 类是抽象的,无法直接使用 2. 对象是类的一个具体实现,可以直接使用 3. 语法 类名 *对象名 = ...