【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 ...
随机推荐
- 浅谈C#关于AOP编程的学习总结
难得在这样一个节日里给写出一篇博客,却没有佳人相约,没办法,这就是一个程(dan)序(shen)猿(gou)的真实生活情景,每天除了coding还是coding.唉..污染各位看官的眼了.好吧,进入正 ...
- VS编译出现 HTTP 错误 403.14 - Forbidden 决绝办法
决绝办法: 运行cmd命令,在控制台面板计入Iis Express目录下.运行提示的的就可以了 appcmd set config /section:system.webServe ...
- C# 进程 和线程
进程 没有应用程序可以看做是一个进程 线程:就是对cpu执行的最小单位 单线程:前台线程和后台线程 带来的问题:假死 net中不能跨线程访问
- 解决UICollectionView ReloadData闪一下(隐式动画)
方式一: [UIView setAnimationsEnabled:NO]; [collectionView performBatchUpdates:^{ [collectionView reload ...
- jQuery分析(2) - $工厂函数分析
前言 从这节进入jQuery的世界,首先从jQuery的入口函数开始了解jQuery()或$是如何运作的,这里我给出了一个最小的例子来分析. 回忆 在进入分析代码前我们回想下jQuery的使用方法有哪 ...
- Spring Security Encryption三种加密方式
Encryption One-way encryption 单项加密,客户端将要传递的值先加密(使用特定的加密方法),将原值和加密好的值传递过去,服务器端将原始数据也进行一次加密(两者加密 ...
- 生成dll文件的示例
看了好多网上写的关于dll文件生成和实用的资料发现多尔不全,都是抄来抄去,有的干脆就是搬用msdn上的原文,实在没有创意和可看的东西.于是本着学和实用的目的自己实践的东西分享给大家. 大前提:使用VS ...
- juquery验证插件validation addMethod方法使用笔记
该方法有三个api接口参数,name,method,messages addMethod(name,method,message)方法 参数 name 是添加的方法的名字. 参数 method 是一个 ...
- preg_replace($pattern, $replacement, $content) 修饰符的奇葩作用
$str = "<span>lin</span> == <span>3615</span>";$pattern = "/& ...
- 【开源】封装HTML5的localstorage
项目名:web-storage-cache 项目地址:https://github.com/WQTeam/web-storage-cache API说明:https://github.com/WQTe ...