#include<stdio.h>
#include<queue>
#include<iostream>
#include<string.h>
#include<algorithm>
#define N 200
using namespace std;
struct
node {
int
x,y,time;
}
start,end,cur,next;
char
map[N][N];
int
visit[N][N][N],k,r,c;
int
dis[4][2]={{1,0},{-1,0},{0,-1},{0,1}};
int
judge(int a,int b,int ti) {
if(
visit[a][b][ti%k])
return
0;
if(
a<1||a>r||b<1||b>c)
return
0;
if(
map[a][b]=='#'&&ti%k!=0)
return
0;
return
1;
}
int
bfs(node start) {
int
i;
memset(visit,0,sizeof(visit));
queue<node>q;
start.time=0;
visit[start.x][start.y][0]=1;
q.push(start);
while(!
q.empty()) {
cur=q.front();
q.pop();
for(
i=0;i<4;i++) {
next.x=cur.x+dis[i][0];
next.y=cur.y+dis[i][1];
next.time=cur.time+1;
if(
judge(next.x,next.y,next.time)) {
if(
next.x==end.x&&next.y==end.y)
return
next.time;
visit[next.x][next.y][next.time%k]=1;
q.push(next);
}
}
}
return -
1;
}
int main() {
int
i,j,t,ans;
scanf("%d",&t);
while(
t--) {
scanf("%d%d%d",&r,&c,&k);
for(
i=1;i<=r;i++)
scanf("%s",map[i]+1);
for(
i=1;i<=r;i++)
for(
j=1;j<=c;j++) {
if(
map[i][j]=='Y') {
start.x=i;
start.y=j;
}
if(
map[i][j]=='G') {
end.x=i;
end.y=j;
}
}

ans=bfs(start);
if(
ans==-1)
printf("Please give me another chance!\n");
else

printf("%d\n",ans);
}
return
0;
}

hdu 2579的更多相关文章

  1. HDU 2579 (记忆化BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2579 题目大意:走迷宫.对于障碍点,只有当前(dep+1)%k才能走,问最少时间. 解题思路: 只有 ...

  2. hdu 2579 Dating with girls(2)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...

  3. hdu 2579 Dating with girls(2) (bfs)

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. HDU 2579/BFS/ Dating with girls(2)

    题目链接 /* 题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间. 关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可. */ #includ ...

  5. http://acm.hdu.edu.cn/showproblem.php?pid=2579

    #include<stdio.h> #include<string.h> #include<queue> #define N 110 int m, n, k, x1 ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. HDU.2734 Quicksum

    Quicksum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  8. hdu 2578 Dating with girls(1) (hash)

    Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. HDU 2578 Dating with girls(1) [补7-26]

    Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. 常用的HTML5 pattern属性

    type="tel" 和 type="number" 的区别 这里还是先那么先交代一下最初遇到的问题.其实无论是tel还是number都不是完美的: type= ...

  2. python工具之myql数据库操作

    import pymysql import config ''' 1.0 简单封装 1.1 添加了insert_id属性,返回insert时返回的主键 1.2 添加了column属性,返回查询的col ...

  3. hadoop的安装和配置

    hadoop安装 在Apache Hadoop主页的下载页面https://hadoop.apache.org/releases.html选择版本进行下载: 下载下来的是压缩包: 将压缩包使用Xftp ...

  4. LN : leetcode 733 Flood Fill

    lc 733 Flood Fill 733 Flood Fill An image is represented by a 2-D array of integers, each integer re ...

  5. return false 的其中一种用法

    return false 的具体是做什么的在这里就不多说了,因为我觉得我形容不明白.....避免大家弄混乱,就不给大家添麻烦了~~ 直接上例子: 1.先看看下面一段代码,指出其中的错误所在: //点击 ...

  6. canvas基础绘制-绚丽倒计时

    效果图: html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  7. 【学习笔记】深入理解js原型和闭包(10)——this

    接着上一节讲的话,应该轮到“执行上下文栈”了,但是这里不得不插入一节,把this说一下.因为this很重要,js的面试题如果不出几个与this有关的,那出题者都不合格. 其实,this的取值,分四种情 ...

  8. Dockerfile 中的 CMD和ENTRYPOINT 两兄弟

    CMD 先说老大 CMD 当一个容器准备好运行之后,需要找一个指定命令来创建一个初始进程并运行. 一,/bin/sh -c 因为某种意义上一个Dockerfile其实可以理解是一个简化版bash 脚本 ...

  9. HashSet LinkedHashSet TreeSet 分析

    1.HashSet分析 hashset 底层是hash表,就是hashMap,是无序的,唯一的.也就是说,它的底层其实就是一个HashMap  key 值的组成值.所以具有唯一性. public Ha ...

  10. Mac 创建软链接

    ln -s /Volumes/dzqExt/source/wukongqipai/wukongqipai/ccclient/Classes/ ./frameworks/runtime-src/     ...