题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1728

思路

BFS

一开始 从开始位置 往四周走 如果能走的话 这个时候 转弯次数都是0

我们的标记不是简单的标记

我们给每个已经访问过的位置 第一次访问时 我们将此时的转弯次数 赋值给它

当下一次 有其他状态 又来访问的时候,我们判断一下 之前已经标记的转弯次数 是比当前的大于等于吗 如果是 那么这个点 就可以继续走下去 如果不是 目前的这个状态就可以不要 相当于剪枝了

有几个坑点

输入的时候 坐标是从1-N 1-M 的

然后输入起始坐标的时候,, x 代表列 y 代表行

AC代码

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<list>
#include<stack>
#include <queue> #define CLR(a, b) memset(a, (b), sizeof(a)) using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e2 + 5; int Move[4][2] = // up 0 down 1 left 2 right 3
{
-1, 0, // up
1, 0, // down
0,-1, // left
0, 1, // right
}; int n, m; int G[maxn][maxn];
int v[maxn][maxn]; int sx, sy, ex, ey, limit; int ans; struct node
{
int x, y;
int step;
int dis;
}; bool ok(int x, int y, int step)
{
if (x < 0 || x >= n || y < 0 || y >= m || G[x][y] == 0 || v[x][y] < step)
return false;
return true;
} void bfs()
{
queue <node> q;
node tmp;
tmp.step = 0;
v[sx][sy] = 1;
for (int i = 0; i < 4; i++)
{
tmp.x = sx + Move[i][0];
tmp.y = sy + Move[i][1];
tmp.dis = i;
if (ok(tmp.x, tmp.y, tmp.step))
{
q.push(tmp);
v[tmp.x][tmp.y] = tmp.step;
}
}
while (!q.empty())
{
node u = q.front(), V;
q.pop();
if (u.x == ex && u.y == ey)
{
if (u.step <= limit)
{
ans = 1;
return;
}
}
if (u.step > limit)
continue;
for (int i = 0; i < 4; i++)
{
V.x = u.x + Move[i][0];
V.y = u.y + Move[i][1];
if (u.dis != i)
V.step = u.step + 1;
else
V.step = u.step;
V.dis = i;
if (ok(V.x, V.y, V.step))
{
q.push(V);
v[V.x][V.y] = V.step;
}
}
} } void init()
{
CLR(G, 0);
CLR(v, 0x3f);
} int main()
{
int t;
cin >> t;
while (t--)
{
init();
scanf("%d%d", &n, &m);
char c;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
scanf(" %c", &c);
if (c == '.')
G[i][j] = 1;
else
G[i][j] = 0;
}
}
scanf("%d%d%d%d%d", &limit, &sy, &sx, &ey, &ex);
sx--, sy--, ex--, ey--;
ans = 0;
bfs();
if (ans)
printf("yes\n");
else
printf("no\n");
} }

HDU - 1728 逃离迷宫 【BFS】的更多相关文章

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

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

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

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

  3. hdu 1728 逃离迷宫 (BFS)

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

  4. hdu 1728 逃离迷宫 BFS加优先队列 DFS()

    http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意就是能否在规定的转弯次数内从起点走到终点.刚走时那步方向不算. 只会bfs(),但想到这题需要记录转弯 ...

  5. HDU 1728 逃离迷宫 BFS题

    题目描述:输入一个m*n的地图,地图上有两种点,一种是 . 表示这个点是空地,是可以走的,另一种是 * ,表示是墙,是不能走的,然后输入一个起点和一个终点,另外有一个k输入,现在要你确定能否在转k次弯 ...

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

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

  7. HDU 1728 逃离迷宫(DFS)

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

  8. HDU 1728 逃离迷宫

    [题目描述 - Problem Description] 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,glo ...

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

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

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

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

随机推荐

  1. 【已解决】 iView-admin 动态路由问题

    IView-admin 在使用的时候 跳转客户详细后,点击其它页面,然后再从选项卡进入页面时,发下控制台 报错,不能正常打开客户详细页面 [vue-router] Route with name 'c ...

  2. pycharm下: conda installation is not found ----一个公开的bug的解决方案

    pycharm  conda installation is not  found ----一个公开的bug的解决方案 pycharm+anaconda 是当前的主流的搭建方案,但是常出现上述问题. ...

  3. Mysql 复制表数据(表结构相同)

    [1]Mysql 复制表数据(表结构相同) -- 方式一: create table table_name_dest as select * from table_name_src; -- 方式二: ...

  4. usermod命令

    usermod 功能: 修改用户 常用参数:-c    账号说明-d    账号家目录-e    密码失效日期-g    主用户组GID-G    次用户组GID-l    账号名称-s    she ...

  5. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps Office新的App模型

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps  Office新的App模型         Office 2 ...

  6. nginx日志自动切分

    #!/bin/bash NGINX_LOG_PATH=/data/nginx-/logs # 昨天 YESTERDAY=$(date -d "yesterday" +%Y-%m-% ...

  7. linux下查找指定时间内修改过的或新建的文件

    1.简单命令 # find -type f \( -newermt '2017-04-19 00:00' -a -not -newermt '2017-04-27 23:59' \) 2.简单实现(参 ...

  8. 智能家居DIY-空气质量检测篇-获取温度和湿度篇

    目录 智能家居DIY-空气质量检测篇-获取空气污染指数 前言 话说楼主终于升级当爸了,宝宝现在5个月了,宝宝出生的时候是冬天,正是魔都空气污染严重的时候,当时就想搞个自动开启空气净化器,由于种种原因一 ...

  9. x-www-form-urlencoded名字的由来

    1 提交的是表单数据 所以用form. 2 提交的形式是以参数放在url后面的形式提交的 例如,以x1=y1&x2=y2&x3=y3的形式放在url后面的形式提交,所以是urlenco ...

  10. php解析xml文件为数组

    $xml = simplexml_load_file($fullfilename); $arr = json_decode(json_encode($xml),true); echo "&l ...