#include<stdio.h>
#include<string.h>
#include<queue>
#define N 110 int m, n, k, x1, x2, y1, y2;
char map[N][N];
int v[N][N][N];//当时间是k的倍数时,障碍消失,之后又重现,所以在平时使用的二维标记数组中再加一维
int d[][] = {{-, }, {, }, {, -}, {, }}; using namespace std; struct node
{
int x, y , stemp;
}; int BFS()
{
node now, next;
int i;
memset(v, , sizeof(v));
queue<node>Q;
now.x = x1;
now.y = y1;
now.stemp = ;
v[x1][y1][] = ;
Q.push(now);
while(!Q.empty())
{
now = Q.front();
Q.pop();
if(now.x == x2 && now.y ==y2)
return now.stemp;
for(i = ; i < ; i++)
{
next.x = now.x + d[i][];
next.y = now.y + d[i][];
next.stemp = now.stemp + ;
if(next.x >= && next.x < m && next.y >= && next.y < n && (map[next.x][next.y] != '#' || next.stemp % k == ) && v[next.x][next.y][next.stemp] == )
{
v[next.x][next.y][next.stemp] = ;
Q.push(next);
}
}
}
return -;
}
int main()
{
int t, i, j, ans;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &m, &n, &k);
for(i = ; i < m ; i++)
scanf("%s", map[i]);
for(i = ; i < m ; i++)
{
for(j = ; j < n ; j++)
{
if(map[i][j] == 'Y')
x1 = i, y1 = j;
else if(map[i][j] == 'G')
x2 = i, y2 = j;
}
}
ans = BFS();
if(ans == -)
printf("Please give me another chance!\n");
else
printf("%d\n", ans);
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=2579的更多相关文章

  1. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...

  2. KMP(http://acm.hdu.edu.cn/showproblem.php?pid=1711)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<stdio.h> #include<math.h> #inclu ...

  3. HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632

    http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...

  4. 待补 http://acm.hdu.edu.cn/showproblem.php?pid=6602

    http://acm.hdu.edu.cn/showproblem.php?pid=6602 终于能够看懂的题解: https://blog.csdn.net/qq_40871466/article/ ...

  5. HDU-1257 导弹拦截系统 http://acm.hdu.edu.cn/showproblem.php?pid=1257

    Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...

  6. KMP应用http://acm.hdu.edu.cn/showproblem.php?pid=2594

    riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aa ...

  7. HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544

    //代码: //方法1:Dijkstra's Algorithm #include<stdio.h> #include<math.h> #include<string.h ...

  8. HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...

  9. HDU 1312 http://acm.hdu.edu.cn/showproblem.php?pid=1312

    #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #de ...

随机推荐

  1. Machine Learning for hackers读书笔记(四)排序:智能收件箱

    #数据集来源http://spamassassin.apache.org/publiccorpus/ #加载数据 library(tm)library(ggplot2)data.path<-'F ...

  2. Machine Learning for hackers读书笔记(二)数据分析

    #均值:总和/长度 mean() #中位数:将数列排序,若个数为奇数,取排好序数列中间的值.若个数为偶数,取排好序数列中间两个数的平均值 median() #R语言中没有众数函数 #分位数 quant ...

  3. Qt之QHeaderView自定义排序(获取正确的QModelIndex)

    简述 前几节中分享过关于自定义排序的功能,貌似我们之前的内容已经可以很好地解决排序问题了,但是,会由此引发一些很难发现的问题...比如:获取QModelIndex索引错误. 下面,我们先来实现一个整行 ...

  4. 报错:对象必须实现 IConvertible;以分隔符进行分割链接concat_ws的使用方法;mysql数据类型转换cast,convert

    错误故障,mysql  服务器上用 concat_ws 函数,连接了一串数字,最后 服务器返回的字段就变成了一个 byte ,而我们想要的类型是  string 类型,那么转换的时候,就报错了. 正确 ...

  5. I.MX6 Linux、Jni ioctl 差异

    /*********************************************************************** * I.MX6 Linux.Jni ioctl 差异 ...

  6. hibernate3和spring整合的一些方式

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. matplotlib 绘制柱状图的几个例子

    1 error bar #!/usr/bin/env python # a bar plot with errorbars import numpy as np import matplotlib.p ...

  8. Apache Conf/Vost/xx.conf 文件配置

    #监听8086端口Listen 8086 NameVirtualHost *:8086#保持绝对一致 <VirtualHost *:> ServerName localhost Serve ...

  9. sessionFactory.getCurrentSession()的引出

    当业务逻辑中需要开启事务执行,业务逻辑也要调用底层操作数据库的函数,那函数也要开启事务操作. 如果用sessionFactory.openSession()的话会引起处理不在同一个事务中,会造成出错. ...

  10. nginx爆出新漏洞 最低限度可造成DDos攻击

    5月9日消息:国内某安全厂商称HTTP代理服务器nginx爆出远程栈缓冲区溢出漏洞,攻击者利用此漏洞可能造成栈溢出,从而执行任意代码,最低限度可造成拒绝服务攻击.目前,官方已经发布安全公告以及相应补丁 ...