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, 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的更多相关文章
- HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...
- 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 ...
- HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632
http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...
- 待补 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/ ...
- HDU-1257 导弹拦截系统 http://acm.hdu.edu.cn/showproblem.php?pid=1257
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...
- KMP应用http://acm.hdu.edu.cn/showproblem.php?pid=2594
riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aa ...
- HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544
//代码: //方法1:Dijkstra's Algorithm #include<stdio.h> #include<math.h> #include<string.h ...
- HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...
- HDU 1312 http://acm.hdu.edu.cn/showproblem.php?pid=1312
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #de ...
随机推荐
- Spring 实践 -IoC
Spring 实践 标签: Java与设计模式 Spring简介 Spring是分层的JavaSE/EE Full-Stack轻量级开源框架.以IoC(Inverse of Control 控制反转) ...
- HDU 2830 Matrix Swapping II
给一个矩阵,依然是求满足条件的最大子矩阵 不过题目中说任意两列可以交换,这是对题目的简化 求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始) 因为排序会影响到h ...
- BZOJ 3653 谈笑风生
ORZ blutrex...... 主席树. #include<iostream> #include<cstdio> #include<cstring> #incl ...
- 旧书重温:0day2【3】 详细解读PEB法 查找kener32地址
题外话:上一篇文章中的 PEB法查找kerner32地址的方法 对TEB.PEB .PE结构 知识要求很高,确实在写汇编代码时候小编 感觉自己能力,信手啪啪一顿乱撸,结果一运行,非法访问了,没办法翻阅 ...
- LeetCode Reverse Nodes in k-Group 每k个节点为一组,反置链表
题意:给一个单链表,每k个节点就将这k个节点反置,若节点数不是k的倍数,则后面不够k个的这一小段链表不必反置. 思路:递归法.每次递归就将k个节点反置,将k个之后的链表头递归下去解决.利用原来的函数接 ...
- .Net dll多个同名的程序集版本冲突共存与通过基本代码或探测定位程序集方案
.Net dll多个同名的程序集版本冲突共存与通过基本代码或探测定位程序集方案 在使用调用程序集的引用中的信息和配置文件中的信息确定了正确的程序集版本之后,并且在公共语言运行时在全局程序集缓存中进行检 ...
- scala学习笔记(5)
偏应用函数 举个例子 def sum(a: Int, b: Int, c: Int) = a + b + c val a = sum _ println(a(1,2,3)) 实际发生的事情是这样的:名 ...
- 转:使用 JMeter 完成常用的压力测试
使用 JMeter 完成常用的压力测试 就目前 Java EE 的平台下开发的软件来说,这种节点通常可能是:Web 服务器.数据库服务器和 JMS 服务器.它们都是请求主要发生的地点,请求频率较其它的 ...
- CentOS7 安装 swoole
sudo pecl install swoole 即可安装.安装完后修改php.ini,加入extension=swoole.so 重启 sudo systemctl restart php-fpm ...
- 传统IT大佬们,路在何方?
[文/ 任英杰] 2014年第一季度季报陆续出台,互联网公司无疑仍是璀璨明星,一路凯歌,而与互联网企业的蒸蒸日上形成鲜明对照的是传统IT企业的集体黯然失色.分析一下传统IT大佬们发布的数据,用友营业收 ...