hdu 1728 逃离迷宫(dFS+优先队列)
求转弯最少的走路方式!!!!
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
int x,y;
int step;
friend bool operator<(node a,node b)
{
return a.step>b.step;
}
};
char map[200][200];
int visit[200][200],n,m,p;
int dir[4][2]={0,1,1,0,-1,0,0,-1};
int judge(int x,int y)
{
if(x>=1&&x<=n&&y>=1&&y<=m&&map[x][y]=='.')
return 1;
return 0;
}
int dfs(int sx,int sy,int dx,int dy)
{
priority_queue<node>q;
int i,x,y;
node cur,next;
cur.x=sx;cur.y=sy;cur.step=-1;
q.push(cur);
visit[sx][sy]=1;
if(sx==dx&&sy==dy)
return 1;
while(!q.empty())
{
next=q.top();
q.pop();
for(i=0;i<4;i++)
{
x=next.x+dir[i][0];
y=next.y+dir[i][1];
while(judge(x,y))//同一方向走到底
{
if(visit[x][y]==0)
{
cur.x=x;
cur.y=y;
cur.step=next.step+1;
if(x==dx&&y==dy&&cur.step<=p)
return 1;
q.push(cur);
visit[x][y]=1;
}
x=x+dir[i][0];
y=y+dir[i][1];
}
}
}
return 0;
}
int main()
{
int i,T,sx,sy,dx,dy;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(visit,0,sizeof(visit));
for(i=1;i<=n;i++)
scanf("%s",map[i]+1);
scanf("%d%d%d%d%d",&p,&sy,&sx,&dy,&dx);
if(dfs(sx,sy,dx,dy))//输入方式坑人
printf("yes\n");
else
printf("no\n");
}
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1728
hdu 1728 逃离迷宫(dFS+优先队列)的更多相关文章
- 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||BFS)
逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
- 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 逃离迷宫
[题目描述 - Problem Description] 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,glo ...
- hdu 1728 逃离迷宫 (BFS)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- hdu 1728 逃离迷宫 BFS加优先队列 DFS()
http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意就是能否在规定的转弯次数内从起点走到终点.刚走时那步方向不算. 只会bfs(),但想到这题需要记录转弯 ...
随机推荐
- [AngularJS] Angular 1.5 multiple transclude
If you know ui-router, multi-transclude should be easy for you also. In previou Angular version < ...
- 【Nginx】事件和连接
不同的操作系统相应不同的事件驱动机制.在Linux 2.6之后使用epoll机制.相应的事件驱动模块是ngx_epoll_module.Nginx的ngx_event_core_module模块依据操 ...
- with admin option 与with grant option
在赋予user 权限或者role 时,常常会用到with admin option 和with grant option,而在使用中,可能会很容易出现混淆的情况,现把他们的相同点和不同点总结如下:相同 ...
- .NET 4.0 兼容 .NET 2.0 的方法
使用.net开发桌面应用,广大亲门最头疼的莫过于客户端部署的问题.基于.net 2.0 的winfrom程序因为 Framework 的分发包大小为20M左右还好解决,不幸的是如果项目中使用了Wcf, ...
- String StringBuffer StringBuilder (转)
转自:http://www.iteye.com/topic/522167 众所周知,String是由字符组成的串,在程序中使用频率很高.Java中的String是一个类,而并非基本数据类型. 不过她却 ...
- c#打开指定设备程序以及网址
//打开计算器 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = @"C:\WINDOWS\ ...
- sqlite编译
1.下载代码:http://www.sqlite.org/download.html ,windows下下载sqlite-amalgamation-xxx.zip和sqlite-dll-win32-x ...
- CSSOM视图模式
相关技术文章: CSSOM视图模式(CSSOM View Module)相关整理 W3C CSSOM View Module
- hadoop容灾能力测试
实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...
- javascript取消disabled属性
jQuery: $("#ID").attr("disabled",false);