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 ...
随机推荐
- Python实现决策树ID3算法
主要思想: 0.训练集格式:特征1,特征2,...特征n,类别 1.采用Python自带的数据结构字典递归的表示数据 2.ID3计算的信息增益是指类别的信息增益,因此每次都是计算类别的熵 3.ID3每 ...
- 让搜狗输入法更符合编程/vim使用的配置
1. “菜单”—“设置属性”—“常用”—“初始状态”里的“中/英文”选项,选中“英文” 2. 设置属性里的“高级”里的“高级模式”,点“英文输入法设置”,“启动时启用英文输入法”选中 3. 按键-中英 ...
- 导Excel数据表
需要把EXcel转换格式:
- spring boot jar启动
1.依赖包输出 记得禁用热加载 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactI ...
- python中一些函数应用
items将一个字典以列表的形式返回,因为字典是无序的,所以返回的列表也是无序的. 例如:a = {"a":1,"b":2} a.items 就是 a ...
- html调用js提示方法名 is not defined处理方法
解决办法(方法名 is not defined): dosave=function(){ alert("方法名在前"); } 下面这种写法有时候会出现错误: function do ...
- js获取上周、本周、下周的时间
//获取上周起始时间结束时间.下周起始时间结束时间开始时间和本周起始时间结束时间;(西方) function getTime(n) { var now = new Date(); var year = ...
- Chrome开发者工具关于网络请求的一个隐藏技能
这个隐藏技能的背景是,最近出于学习目的,我写了一个百度贴吧的网络爬虫,专门爬取一些指定主题的贴吧帖子. 抓取帖子用的JavaScript函数如下: function getPostByAJAX(req ...
- linux ABORT的应用详解
NAME ABORT - 退出当前事务 SYNOPSIS ABORT [ WORK | TRANSACTION ] DESCRIPTION 描述 ABORT 回卷当前事务并且废弃所有当前事务中做的更新 ...
- class 写在 import的位置 类的名字第一个字母大写 后面没括号 ES6
class 写在 import的位置 类的名字第一个字母大写 后面没括号 class ObTableDataClass {}或者 const ObTableDataClass = class { in ...