逃离迷宫 HDU - 1728(bfs)
逃离迷宫
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34147 Accepted Submission(s): 8333
第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对应行。
Sample Input
2
5 5
...**
*.**.
.....
.....
*....
1 1 1 1 3
5 5
...**
*.**.
.....
.....
*....
2 1 1 1 3
Sample Output
no
yes
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=; int n,m;
int max_turn;
int start_x,start_y,end_x,end_y;
char a[maxn][maxn];
bool vis[maxn][maxn];
int dir[][]={,,,,,-,-,}; struct node
{
int x,y;
int turn_num;
}; int bfs()
{
queue<node>que;
node q1;
q1.x=start_x;
q1.y=start_y;
q1.turn_num=-;
que.push(q1);
vis[start_x][start_y]=;
while(!que.empty())
{
node q2=que.front();
que.pop();
if(q2.x==end_x && q2.y==end_y && q2.turn_num<=max_turn)
return ;
q1.turn_num=q2.turn_num+;
for(int i=;i<;i++)
{
q1.x=q2.x+dir[i][];
q1.y=q2.y+dir[i][];
while(q1.x>= && q1.x<=n && q1.y>= && q1.y<=m && a[q1.x][q1.y]=='.' )
{
if(!vis[q1.x][q1.y])
{
que.push(q1);
vis[q1.x][q1.y]=;
}
q1.x=q1.x+dir[i][];
q1.y=q1.y+dir[i][];
}
} }
return ;
} int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
cin>>a[i][j];
cin>>max_turn>>start_y>>start_x>>end_y>>end_x;
memset(vis,,sizeof(vis));
if(bfs())
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return ;
}
逃离迷宫 HDU - 1728(bfs)的更多相关文章
- 逃离迷宫(HDU 1728 BFS)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu - 1728逃离迷宫 && hdu - 1175 连连看 (普通bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 这两道题花了一下午的时候调试,因为以前做过类似的题,但是判断方向的方法是错的,一直没发现啊,真无语. 每个 ...
- hdu 1728 bfs **
简单bfs,记录好状态即可 #include<cstdio> #include<iostream> #include<algorithm> #include< ...
- 逃离迷宫 HDU1728 (bfs)
和连连看非常相似 都是求转向的BFS 改了一下就上交了... #include<cstdio> #include<cstring> #include<algorith ...
- HDU 1728:逃离迷宫(BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有 ...
- 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)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- HDU 1728 逃离迷宫(DFS||BFS)
逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
随机推荐
- jQuery banner切换插件
今天学写了一个基于jQuery焦点图切换插件,有不对的地方还请多多指教,不多说下面是代码: 1.引jQuery库 <script src="http://code.jquery.com ...
- Windows7&IIS7.5部署Discuz全攻略
组长说在内网部署一个论坛,这可难不倒我,装个Discuz嘛.部署环境就一台普通的PC,四核i3,Windows7.这就开搞了. 准备工作 系统是Windows 7 专业版,自带IIS7.5(家庭版不带 ...
- 一道笔试题和UML思想 ~
一句软件工程界的名言,让我想起了一个和一道笔试题有关的故事.希望更多的人了解 UML 背后的思想比他的语法更重要,是笔者写作本文的一点小愿望. 一.从一句软件工程名言说起 对很多事情的处理上,东西方都 ...
- 数据库2_sqlHelper
封装一个受影响的行 public static int ExcuteNonQuery(string sqlText,params SqlParameter[] parameters) { using ...
- Myeclipse连接数据库删除数据库(JDBC)
package com.test.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Pr ...
- (转)VC得到可用的串口列表
//枚举串口 //参数:bEnablePort,哪个串口有效,bEnablePort[0]表示COM1,bEnablePort[n-1]表示COMn //返回值:有效的串口个数 int EnumAll ...
- jmeter参考网址
http://blog.csdn.net/dongdong9223/article/details/49248979 http://blog.csdn.net/hjh00/article/detail ...
- AE开发关于OnMapReplaced方法的使用原理
The OnMapReplaced event is triggered whenever the IMapControl2::Map is replaced by another map, such ...
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...
- UVA 690 PipelineScheduling 位运算+dfs+剪枝
一开始最容易想到间隔最多为n,但是结点还是太多了,需要优化. 预处理:预判一下并保存下一个可以放的位置距离之前的距离.这样可以减少很多判断. 最优化剪枝:如果当前长度+剩下没放的程序*最短间隔如果大于 ...