HDU 2579/BFS/ Dating with girls(2)
/*
题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间。
关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可。
*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100+5;
int vis[maxn][maxn][15];
int dir[4][2]={0,1,1,0,0,-1,-1,0};
char maze[maxn][maxn];
int sx,sy,ex,ey;
int n,m,k;
void init()
{
memset(vis,0,sizeof(vis));
}
struct node
{
int x;
int y;
int time;
};
int BFS()
{
node now;
now.x=sx;
now.y=sy;
now.time=0;
queue<node>que;
que.push(now);
while(!que.empty())
{
now=que.front();
que.pop();
if(now.x==ex&&now.y==ey)
return now.time;
for(int i=0;i<4;i++)
{
int x=now.x+dir[i][0];
int y=now.y+dir[i][1];
int t=now.time+1;
int mod=t%k;
if(x>=1&&x<=n&&y>=1&&y<=m)
{
if(maze[x][y]!='#'&&vis[x][y][mod]==0)
{
vis[x][y][mod]=t;
node next=(node){x,y,t};
que.push(next);
}
else if(maze[x][y]=='#'&&mod==0&&vis[x][y][mod]==0)
{
vis[x][y][mod]=t;
node next=(node){x,y,t};
que.push(next);
}
}
}
}
return -1;
}
int main ()
{
int T;scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
init();
for(int i=1;i<=n;i++)
{
scanf("%s",maze[i]+1);
for(int j=1;j<=m;j++)
if(maze[i][j]=='Y')
sx=i,sy=j;
else if(maze[i][j]=='G')
ex=i,ey=j;
}
int ans=BFS();
if(ans==-1)
printf("Please give me another chance!\n");
else
printf("%d\n",ans);
}
return 0;
}
HDU 2579/BFS/ Dating with girls(2)的更多相关文章
- 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 Dating with girls(2)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...
- 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 ...
- hdu 2578 Dating with girls(1)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 3784 继续xxx定律 & HDU 2578 Dating with girls(1)
HDU 3784 继续xxx定律 HDU 2578 Dating with girls(1) 做3748之前要先做xxx定律 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ ...
- hdu 2578 Dating with girls(1) 满足条件x+y=k的x,y有几组
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- BFS:HDU2597-Dating with girls(2) (分时间标记状态)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- 转:MongoDB介绍及下载与安装
非原创,我也是转载(Here)过来备份一下.关于MongoDB园子里有个系列讲的不错的,点击此处跳转 MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系 ...
- Computation expressions: Introduction
本文仅为对原文的翻译,主要是记录以方便以后随时查看.原文地址为http://fsharpforfunandprofit.com/posts/computation-expressions-intro/ ...
- kettle新建资源库(4)
工具中找资源库或者CTRL+R
- Linux系统英文切换中文
Centos系统作为开源最优秀的Linux版本,很多时候作为服务器使用.由于很多linux初学者不太习惯字符界面操作.一般都会安装图形界面,可是安装之后发现是英文的怎么设置让系统显示为中文呢?咗嚛本经 ...
- php缓存总结
php缓存技术: 1.全页面静态化缓存;2.页面部分缓存;3.数据缓存;4.查询缓存;5.按内容变更进行缓;6.内存式缓存;7.apache缓存模块;8.php APC缓存扩展;9.Opcode缓存. ...
- LightOJ 1337 F - The Crystal Maze (bfs)
Description You are in a plane and you are about to be dropped with a parasuit in a crystal maze. As ...
- Openjudge-计算概论(A)-完美立方
描述: a的立方 = b的立方 + c的立方 + d的立方为完美立方等式.例如12的立方 = 6的立方 + 8的立方 + 10的立方 .编写一个程序,对任给的正整数N (N≤100),寻找所有的四元组 ...
- MongoDB执行计划分析详解
要保证数据库处于高效.稳定的状态,除了良好的硬件基础.高效高可用的数据库架构.贴合业务的数据模型之外,高效的查询语句也是不可少的.那么,如何查看并判断我们的执行计划呢?我们今天就来谈论下MongoDB ...
- redis高级实用特性(1)
1.安全性 2.主从复制 3.事务处理 4.持久化机制 5.发布订阅消息 6.虚拟内存的使用 安全性:设置客户端连接后进行任何其他指定前需要使用的密码 警告:因为redis速度相当快,所以在一台比较好 ...
- 查看Linux系统文本编码-方便修改ssh编码一致
首先,Linux系统发行的时候全世界都一样,系统是中文的还是英文的完全取决于你选择的语言包.不同国家的人在安装使用的时候选择属于自己国家的语言包,应用程序中的语言也不是写死的,它根据系统的设置来调用相 ...