HDU2579(bfs迷宫)
Dating with girls(2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3006 Accepted Submission(s): 864
The Maze is very strange. There are many stones in the maze. The stone will disappear at time t if t is a multiple of k(2<= k <= 10), on the other time , stones will be still there.
There are only ‘.’ or ‘#’, ’Y’, ’G’ on the map of the maze. ’.’ indicates the blank which you can move on, ‘#’ indicates stones. ’Y’ indicates the your location. ‘G’ indicates the girl's location . There is only one ‘Y’ and one ‘G’. Every seconds you can move left, right, up or down.

The next r line is the map’s description.
#include <cstdio>
#include <string.h>
#include <queue>
using namespace std;
const int MAXN=;
struct Node{
int y,x,step;
Node(){}
Node(int y,int x,int step)
{
this->y=y;
this->x=x;
this->step=step;
}
};
char mz[MAXN][MAXN];
int n,m,k;
int sy,sx;
int dy[]={,,,-};
int dx[]={,,-,};
int vis[MAXN][MAXN][MAXN];
void bfs()
{
memset(vis,,sizeof(vis));
queue<Node> que;
que.push(Node(sy,sx,));
vis[sy][sx][%k]=;
while(!que.empty())
{
Node now=que.front();que.pop();
if(mz[now.y][now.x]=='G')
{
printf("%d\n",now.step);
return ;
}
for(int i=;i<;i++)
{
int ny=now.y+dy[i];
int nx=now.x+dx[i];
int ns=now.step+;
if(<=ny&&ny<n&&<=nx&&nx<m&&!vis[ny][nx][ns%k])
{
if(mz[ny][nx]!='#')
{
vis[ny][nx][ns%k]=;
que.push(Node(ny,nx,ns));
}
else
{
if(ns%k==)
{
vis[ny][nx][ns%k]=;
que.push(Node(ny,nx,ns));
}
}
}
}
}
printf("Please give me another chance!\n");
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++)
{
scanf("%*c");
for(int j=;j<m;j++)
{
scanf("%c",&mz[i][j]);
if(mz[i][j]=='Y')
{
sy=i;
sx=j;
}
}
}
bfs();
}
return ;
}
HDU2579(bfs迷宫)的更多相关文章
- bfs—迷宫问题—poj3984
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20591 Accepted: 12050 http://poj ...
- uva 816 - Abbott's Revenge(有点困难bfs迷宫称号)
是典型的bfs,但是,这个问题的目的在于读取条件的困难,而不是简单地推断,需要找到一种方法来读取条件.还需要想办法去推断每一点不能满足条件,继续往下走. #include<cstdio> ...
- BFS迷宫搜索路径
#include<graphics.h> #include<stdlib.h> #include<conio.h> #include<time.h> # ...
- bfs迷宫
链接:https://ac.nowcoder.com/acm/contest/338/BSleeping is a favorite of little bearBaby, because the w ...
- BFS迷宫问题
链接:https://ac.nowcoder.com/acm/challenge/terminal来源:牛客网 小明现在在玩一个游戏,游戏来到了教学关卡,迷宫是一个N*M的矩阵. 小明的起点在地图中用 ...
- 【OpenJ_Bailian - 2790】迷宫(bfs)
-->迷宫 Descriptions: 一天Extense在森林里探险的时候不小心走入了一个迷宫,迷宫可以看成是由n * n的格点组成,每个格点只有2种状态,.和#,前者表示可以通行后者表示不 ...
- ACM/ICPC 之 BFS-简单障碍迷宫问题(POJ2935)
题目确实简单,思路很容易出来,难点在于障碍的记录,是BFS迷宫问题中很经典的题目了. POJ2935-Basic Wall Maze 题意:6*6棋盘,有三堵墙,求从给定初始点到给定终点的最短路,输出 ...
- (BFS)poj2935-Basic Wall Maze
题目地址 题目与最基本的BFS迷宫的区别就是有一些障碍,可以通过建立三维数组,标记某个地方有障碍不能走.另一个点是输出路径,对此建立结构体时要建立一个pre变量,指向前一个的下标.这样回溯(方法十分经 ...
- 3299: [USACO2011 Open]Corn Maze玉米迷宫
3299: [USACO2011 Open]Corn Maze玉米迷宫 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 137 Solved: 59[ ...
随机推荐
- id和NSObject *和instanceType的区别与联系
id 被成为万能指针,也就是可以指向任何对象. NSObject * 本身就是定义指向NSObject类型的指针. 那么这两者有什么区别吗? 这两者都是既可以作为返回值,又可以作为变量修饰.而其主要区 ...
- 12.常见模块time、json模块
1.time模块 import time #python中最基本的时间模块 time.time() #时间戳 (1970年1月1日00:00:00后经过的浮点秒数) time.localtime(ti ...
- Golang 高性能UDP Server实现
通过Goroutine实现UDP消息并发处理 package main import ( "net" "fmt" "os" ) // 限制g ...
- python里两种遍历目录的方法
os.walk 函数声明:os.walk(top,topdown=True,onerror=None) (1)参数top表示需要遍历的顶级目录的路径. (2)参数topdown的默认值是“True”表 ...
- Cisco路由器端口
Cisco的设备管理有很多种方式,如Console.HTTP.TTY.VTY或其它网管软件,但我们远程管理较为常用的一种方式肯定是VTY方式. VTY在Cisco的不同系列产品中,都有一定数量的VTY ...
- Spring的AOP面向切面编程
什么是AOP? 1.AOP概念介绍 所谓AOP,即Aspect orientied program,就是面向方面(切面)的编程. 功能: 让关注点代码与业务代码分离! 关注点: 重复代码就叫做关注点: ...
- 安装配置Apollo-Prota web中心平台
首先要求2g以上内存哈,JDK1.8 搭建数据库 创建表 apollo-build-scripts-master 整个阿波罗环境包 使用一个命令启动整个阿波罗服务环境 创建两个数据库 分别为:apol ...
- 字符串问题之 去掉字符串中连续出现K个0的子串
字符串中刚好出现K个连续的‘O’,则把K个连续‘O’字符去除,返回处理后的字符串 比如 str="AOOOOOBOOO" k=3, 返回“AOOOOOB” 这个题的解决思路也有 ...
- 偏远小渔村选手的noip2017游记
这次noip估计是我初中最后一次比赛了,毕竟初三狗还要准备中考,要是中考挂了就GG了. 在最终成绩的榜上,我看到我成绩400,非常意外(你们这群大佬赛前天天奶我,还好不是毒奶),更意外的是全省竟然只有 ...
- java深入探究12-框架之Spring
1.引入Spring 我们在搭建框架时常常会解决问题:对象创建,对象之间依赖关系如何处理,Spring就是来解决这类问题的:控制反转依赖注入 2.环境搭建 1)下载源码:其中3.0以下版本源码中有Sp ...