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 ...
随机推荐
- 【笨嘴拙舌WINDOWS】Dj,oh!nonono,It is about DC
“DC: Device content 设备描述表.通常指显示器,或者打印机设备的描述” 如果你不是从事打印机方面的编程,那么就可以将DC简单的理解为显示器的属性表.WINDOWS将内存里面的东西通过 ...
- Qt Linguist介绍
简介 Qt提供了一款优秀的支持Qt C++和Qt Quick应用程序的翻译工具.发布者.翻译者和开发者可以使用这款工具来完成他们的任务. 发布者:承担了全面发布应用程序的责任.通常,他们协调开发者和翻 ...
- UVa 674 Coin Change【记忆化搜索】
题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...
- spring、springmvc、mybatis整合笔记
这段时间上一个项目刚做完,下一个项目还没开始,趁这个时候来认真总结一下上个项目使用的ssm开发框架.由于,项目中关于使用ssm这部分的代码和配置是我们项目的整体架构师一个独立完成的,我们只负责业务部分 ...
- myeclipes准备工作
设置jsp中默认编码为utf-8
- xunsearch迅搜体验
安装与启动 http://www.xunsearch.com/doc/php/guide/start.installation 编写配置文件 http://www.xunsearch.com/doc/ ...
- yaf框架流程二
这篇讲讲yaf的配置文件,首先上我的配置代码: [common] ;必选配置 ;application.directory String 应用的绝对目录路径 ;可选配置 ;名称 值类型 默认值 说明 ...
- WebView增加一个水平Progress,位置、长相随意
实际效果可以参看微信的web页面进度条 本质就是通过addView及对WebView 页面进度进行监听 先看看这个自定义的DrawableId,我们参照系统默认实现的方法写一个自己的 <la ...
- springmvc 入门级教程
1.先看下目录结构 2.引用所需的jar文件 3.web.xml 配置如下 <?xml version="1.0" encoding="UTF-8"?&g ...
- poj 3254(状态压缩基础题)
题意:就是你给一个n行m列的矩阵,矩阵里的元素由0和1组成,1代表肥沃的土地可以种植作物,0则不可以种植作物,并且相邻的土地不能同时种植作物,问你有多少种种植方案. 分析:这是我做的第一道状态压缩dp ...