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 ...
随机推荐
- Windows API函数大全四
10. API之硬件与系统函数 ActivateKeyboardLayout 激活一个新的键盘布局.键盘布局定义了按键在一种物理性键盘上的位置与含义 Beep 用于生成简单的声音 CharToOem ...
- Intent实现界面跳转、程序跳转
一个程序往往由多个界面组成,界面之间的跳转,实质是Activity之间的跳转. 从当前程序跳转到其它程序,实质是启动了目标程序的入口Activity. Intent被称为意图,常用于组件之间的交互,可 ...
- Ajax深入理解
Ajax Asynchronous JavaScript and XML 异步的JavaScript和XML ajax通过与后台服务器进行少量的数据交换,ajax可以使页面实现异步更新,即不需要重新 ...
- elasticsearch 2.4.0安装说明
首先从官网下载安装包,是个压缩文件,然后解压 在es目录下找到es的配置文件 修改集群(cluster)名称 PS:一般情况下一台机只部署一个es程序,也就是一个集群,默认集群名是ewater_mai ...
- iOS9 开发新特性 Spotlight使用
1.Spotloight是什么? Spotlight在iOS9上做了一些新的改进, 也就是开放了一些新的API, 通过Core Spotlight Framework你可以在你的app中集成Spotl ...
- php中的define()函数
<?php define("PI",3.1415926); //定义常量 $r=12;//定义圆半径 echo "半径为12的单位的圆的面积".PI*($ ...
- std::map插入已存在的key时,key对应的内容不会被更新
std::map插入已存在的key时,key对应的内容不会被更新,如果不知道这一点,可能会造成运行结果与预期的不一致 “Because element keys in a map are unique ...
- 【HEVC帧间预测论文】P1.5 Fast Coding Unit Size Selection for HEVC based on Bayesian Decision Rule
Fast Coding Unit Size Selection for HEVC based on Bayesian Decision Rule <HEVC标准介绍.HEVC帧间预测论文笔记&g ...
- vim下ctrl + s 僵死问题的解决
vim下ctrl + s 僵死问题的解决 vim 使用vim习惯性手残Ctrl+S ,解决方法 : Ctrl + Q 就能恢复了
- 原创Couldn't read packet: Connection reset by peer 错误排查思路(推荐)
作为一个运维 不是你懂多少知识才是你的价值 你有幸能遇到多少错误才是你的最大的价值 知识 你有我有大家有 错误我有你没有 这便是我的价值 我遇到一个错误 蛮难遇到的一个错误 所以想分享给大家 下面我 ...