hdu 1728 逃离迷宫 (BFS)
逃离迷宫
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 44 Accepted Submission(s) : 23
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
第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对应行。
Output
Sample Input
2
5 5
...**
*.**.
.....
.....
*....
1 1 1 1 3
5 5
...**
*.**.
.....
.....
*....
2 1 1 1 3
Sample Output
no
yes
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,m,sx,sy,tx,ty,i,k,t;
char mp[][];
int vis[][];
int dr[][]={{,},{,},{-,},{,-} };
struct node
{
int x,y,k;
}; int check(int x,int y)
{
if (x>= && x<n && y>= && y<m) return ;
else return ;
}
int bfs()
{
node p;
queue<node> s;
p.x=sx;
p.y=sy;
p.k=-;
s.push(p);
vis[sx][sy]=;
while(!s.empty())
{
node q=s.front();
s.pop();
for(int i=;i<;i++)
{
int xx=q.x+dr[i][];
int yy=q.y+dr[i][];
while(mp[xx][yy]!='*' && check(xx,yy))
{
p.x=xx;
p.y=yy;
p.k=q.k+;
if (!vis[xx][yy])
{
s.push(p);
vis[xx][yy]=;
}
if (xx==tx && yy==ty)
if (p.k<=k)return ;
else return ;
xx=xx+dr[i][];
yy=yy+dr[i][]; }
}
}
return ;
}
int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%s",&mp[i]);
scanf("%d%d%d%d%d",&k,&sy,&sx,&ty,&tx);
sy--; sx--; ty--; tx--;
memset(vis,,sizeof(vis));
if(bfs())printf("yes\n");
else printf("no\n");
}
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加优先队列 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 ...
随机推荐
- 关于socket客户端接收不定长数据的解决方案
#!/usr/bin/env python3.5 # -*-coding:utf8-*- """ 本实例客户端用于不断接收不定长数据,存储到变量res "&qu ...
- matlab显示原图和灰度直方图
**只会显示灰度直方图I = imread('*.bmp') %图必须是灰度图,或者转换为灰度图I=rgb2gray(I);imshow(I);imhist(I); **同时出现在一个平面上I = i ...
- samba连接提示“找不到网络路径”
在运行里面输入services.msc,打开服务管理界面. 根据服务的描述,找到了TCP/IP NetBIOS Helper服务描述中提到TCP/IP NetBIOS Helper服务能使用户能够共享 ...
- zabbix3.2在lamp环境安装
zabbix官网下载zabbix-3.2.1.tar.gz wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20 ...
- .Net_把文件数据添加到数据库中(面试题)
一个文本文件含有如下内容: 4580616022644994|3000|赵涛 4580616022645017|6000|张屹 4580616022645090|3200|郑欣夏 上述文件每行为一个转 ...
- memcached + php 扩展 for ubuntu
1.安装memcached apt-get install memcached 2.安装php memcached 扩展 apt-get install php5-memcache 3.启动memca ...
- android抓日志
1. adb logcat -c 清楚以前的日志 adb logcat -s 过滤 adb logcat -s *:E adb logcat -v 指定输出的格式 adb logcat -v brie ...
- Chapter 2 Open Book——4
I walked to Biology with more confidence when, by the end of lunch, he still hadn't showed. 经过中午饭之后我 ...
- apt-get 总结
转自: apt-get 总结 1.apt-get install <package_name> install a new package. 2.apt-get build-dep < ...
- JavaScript高级程序设计:第八章
1.window对象——BOM的核心 BOM的核心对象时window,它表示浏览器的一个实例.在浏览器中,window对象有双重角色,它既是通过javascript访问浏览器窗口的一个接口,又是ECM ...