hdu 2579
#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的更多相关文章
- HDU 2579 (记忆化BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2579 题目大意:走迷宫.对于障碍点,只有当前(dep+1)%k才能走,问最少时间. 解题思路: 只有 ...
- hdu 2579 Dating with girls(2)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...
- 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 ...
- HDU 2579/BFS/ Dating with girls(2)
题目链接 /* 题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间. 关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可. */ #includ ...
- 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 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU.2734 Quicksum
Quicksum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- 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 ...
- 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 ...
随机推荐
- 洛谷P3254 圆桌问题(最大流)
题意 $m$个不同单位代表参加会议,第$i$个单位有$r_i$个人 $n$张餐桌,第$i$张可容纳$c_i$个代表就餐 同一个单位的代表需要在不同的餐桌就餐 问是否可行,要求输出方案 Sol 比较zz ...
- DOM编程练习(慕课网题目)
编程练习 制作一个表格,显示班级的学生信息. 要求: 1. 鼠标移到不同行上时背景色改为色值为 #f2f2f2,移开鼠标时则恢复为原背景色 #fff 2. 点击添加按钮,能动态在最后添加一行 3. 点 ...
- es6语法错误
哇,今天折腾了好久解决了一个问题,记录一下. 错误: 解决方法:配置babel,将es6语法转换成es5语法 1. 全局安装babel: npm install babel-cli -g 2. 本地安 ...
- How exception works ?
这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=28 February 18, 2013 How exception work ...
- 【HEVC帧间预测论文】P1.6 A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence
A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence <HEVC标准介绍.HEVC帧间预测论文笔记&g ...
- Java遍历HashMap并修改(remove)
遍历HashMap的方法有多种,比如通过获取map的keySet, entrySet, iterator之后,都可以实现遍历,然而如果在遍历过程中对map进行读取之外的操作则需要注意使用的遍历方式和操 ...
- SqlServer 2008 创建测试数据
包含要点: 数据库的循环 . insert select 句式 . 随机数(rand()函数).绝对值(abs()函数) ) ) DECLARE @randomvalue float SET @s ...
- android 代码中及xml中设置透明
在布局文件的属性中,比如要设置一个LineaerLayout的背景为灰色透明.首先查RGB颜色表灰色是:#9E9E9E,AA代表透明,(透明度从00到FF,00表示完全透明),所以,设置其属性:and ...
- 洛谷 U10206 Cx的治疗
题目背景 「Cx的故事」众所周知,Cx是一个宇宙大犇.由于Cx在空中花园失足摔下,导致他那蕴含着无穷智慧的大脑受到了严重的损伤,许多的脑神经断裂.于是,Cx的wife(有么?)决定请巴比伦最好的医师治 ...
- elasticsearch插入索引文档 对数字字符串的处理
对于字符串在搜索匹配的时候,字符串是数字的话需要匹配的是精准匹配,如果是部分匹配字符串的话,需要进行处理,把数字型字符串作为一个字符中的数组表示插入之后显示如下: 如果插入之后显示如画线部分的话,则表 ...