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[ ...
随机推荐
- Eclipse引入BASE64Encoder的问题
在代码中引用了BASE64Encoder,上面显示的错误信息如下: Access restriction: The type BASE64Encoder is not accessible due t ...
- 字符串处理sdut 2411
题目:http://www.sdutacm.org/sdutoj/problem.php?action=showproblem&problemid=2411 关于字符串处理的题,此题坑点很多w ...
- Qt QT的IO流 QT输入输出
1. QFile QDataStream 读写文件 二进制读写文件 #include <QApplication> #include <QtGui> #include < ...
- hdoj1012--u Calculate e
Problem Description A simple mathematical formula for e is where n is allowed to go to infinity. Thi ...
- 《Think in Java》(七)复用类
Java 中复用代码的方式就是复用类,复用类的方式有: 组合 继承 代理(并没有啥高深的含义,只是在使用类A前,新增了类B,让类B的每个方法去调用类A中对应的方法,也就是说类B代理了类A...不过我还 ...
- windows live writer 原始图片大小设置
点击图片,右面对图片参数进行设置,然后点击保存默认设置. 那么以后再插入图片,就不要重新操作了.
- Nodejs + TypeScript
Node.js https://nodejs.org https://nodejs.org/en/download/ win: msi mac: pkg linux: tar.xz source co ...
- Oracle删除步骤
1.Oracle卸载要求比较严格,不能简单的卸载就完事了:当然Oracle卸载也没有那么难,只是步骤比较多.Oracle10g还是Oracle11g卸载步骤都是一样的.下边详细介绍一下. 找到Orac ...
- 1.Linux和Unix区别
整理来源于网络:http://blog.csdn.net/xiaojianpitt/article/details/6377419 有很多初学Linux的人比较关心Linux和windows的区别,这 ...
- Zeroc Ice 发布订阅者之demo Icestorm之clock
刚刚在服务端(192.168.0.113)和客户端跑通(192.168.0.188),在这里记录,作为备忘. 第一步:读readme,先用vs2010生成subscriber.exe和publishe ...