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

Problem Description
If you have solved the problem Dating with girls(1).I think you can solve this problem too.This problem is also about dating with girls. Now you are in a maze and the girl you want to date with is also in the maze.If you can find the girl, then you can date with the girl.Else the girl will date with other boys. What a pity! 
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.
 
Input
The first line contain an integer T. Then T cases followed. Each case begins with three integers r and c (1 <= r , c <= 100), and k(2 <=k <= 10).
The next r line is the map’s description.
 
Output
For each cases, if you can find the girl, output the least time in seconds, else output "Please give me another chance!".
 
Sample Input
1
6 6 2
...Y..
...#..
.#....
...#..
...#..
..#G#.
 
Sample Output
7
 
思路:若重新走到某位置所需的步数模K的值不同,那么可重复进队。否则意味着进入死循环。
#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迷宫)的更多相关文章

  1. bfs—迷宫问题—poj3984

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20591   Accepted: 12050 http://poj ...

  2. uva 816 - Abbott&#39;s Revenge(有点困难bfs迷宫称号)

    是典型的bfs,但是,这个问题的目的在于读取条件的困难,而不是简单地推断,需要找到一种方法来读取条件.还需要想办法去推断每一点不能满足条件,继续往下走. #include<cstdio> ...

  3. BFS迷宫搜索路径

    #include<graphics.h> #include<stdlib.h> #include<conio.h> #include<time.h> # ...

  4. bfs迷宫

    链接:https://ac.nowcoder.com/acm/contest/338/BSleeping is a favorite of little bearBaby, because the w ...

  5. BFS迷宫问题

    链接:https://ac.nowcoder.com/acm/challenge/terminal来源:牛客网 小明现在在玩一个游戏,游戏来到了教学关卡,迷宫是一个N*M的矩阵. 小明的起点在地图中用 ...

  6. 【OpenJ_Bailian - 2790】迷宫(bfs)

    -->迷宫  Descriptions: 一天Extense在森林里探险的时候不小心走入了一个迷宫,迷宫可以看成是由n * n的格点组成,每个格点只有2种状态,.和#,前者表示可以通行后者表示不 ...

  7. ACM/ICPC 之 BFS-简单障碍迷宫问题(POJ2935)

    题目确实简单,思路很容易出来,难点在于障碍的记录,是BFS迷宫问题中很经典的题目了. POJ2935-Basic Wall Maze 题意:6*6棋盘,有三堵墙,求从给定初始点到给定终点的最短路,输出 ...

  8. (BFS)poj2935-Basic Wall Maze

    题目地址 题目与最基本的BFS迷宫的区别就是有一些障碍,可以通过建立三维数组,标记某个地方有障碍不能走.另一个点是输出路径,对此建立结构体时要建立一个pre变量,指向前一个的下标.这样回溯(方法十分经 ...

  9. 3299: [USACO2011 Open]Corn Maze玉米迷宫

    3299: [USACO2011 Open]Corn Maze玉米迷宫 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 137  Solved: 59[ ...

随机推荐

  1. Android LCD(一):LCD基本原理【转】

    本文转载自:http://blog.csdn.net/longxiaowu/article/details/24787597 关键词:Android LCD TFT 液晶 偏光片 彩色滤光片  背光 ...

  2. SQL Server 字符串拼接与拆分 string varchar Split and Join

    1.Split    SQL Server 2008 新语法: DECLARE @str VARCHAR(MAX) SET @str = REPLACE(@teeIDs, ',', '''),(''' ...

  3. poj 2762 Going from u to v or from v to u?【强连通分量缩点+拓扑排序】

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15812 ...

  4. C#中利用WebBrowser控件,获得HTML源码

    最近获得网页的几个老程序都不能用了. 我原来用 如下代码获得网页html 源码: <pre name="code" class="csharp"> ...

  5. 【转载】树链剖分.By.Xminh

    轻重链剖分 其实就是俗称的树链剖分. PS:树链剖分不止有轻重链剖分.但是大多数时候的树链剖分指的就是轻重链剖分. dfs序 给树的节点重新编号,使得任意一个节点满足子树的dfs序都比它要大,而且它子 ...

  6. Hive数据类型总结

    转载自:http://blog.csdn.net/chenxingzhen001/article/details/20901045 Hive的内置数据类型可以分为两大类:(1).基础数据类型:(2). ...

  7. 根据图片名字在drawable中得到图片

    int imageId = context.getResources().getIdentifier("图片的名字","drawable", "包名& ...

  8. Jquery Ajax模版

    $.ajax({ type: "GET", url: "test.json", data: {username:'tt', content:'tt'}, dat ...

  9. php如何查看扩展是否开启

    php如何查看扩展是否开启 一.总结 一句话总结:php -m 1.查看php已安装扩展命令 ? php -m 2.phpinfo();这是最常用的方法,但那么多扩展一时还真不太好找.? 3.exte ...

  10. Spinner使用二

    Spinner使用二 一.效果图 二.方法及核心函数 三.代码 后面补