题目链接

/*
题意是是传统的迷宫加上一个条件,墙壁在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)的更多相关文章

  1. 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 ...

  2. hdu 2579 Dating with girls(2)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...

  3. 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 ...

  4. 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 ...

  5. hdu 2578 Dating with girls(1)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...

  6. hdoj 2579 Dating with girls(2)【三重数组标记去重】

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 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+ ...

  8. 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 ...

  9. BFS:HDU2597-Dating with girls(2) (分时间标记状态)

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. C库 - 常用文件IO函数

    #include<stdio.h> 0. 文件打开关闭FILE *fp = fopen("C:\\a.dat","wb+");fclose(fp); ...

  2. for、while循环的洪荒之力

    在python里,如果说print语句是用得最多的话,那么,要我说,除了for语句,谁都不敢认老二. 下面,让我们来看看for语句能搞出什么花样 1. 计时(无限次数) 说到计时,我们先来试下显示当前 ...

  3. incallui中如何查询联系人数据

    联系人信息显示在CallCard中,提示当前正在通话的联系人号码.姓名.头像.号码类型等信息: 代码中在两个地方发起对当前联系人的查询, Init():startContactInfoSearch(c ...

  4. MVC DisplayTemplates and EdiotrTemplates.

    我们在mvc项目里经常要对枚举,日期,副文本输入,我们可以用笨拙的方法去view页面里绑定呈现的html内容,而且这种办法不能重用,也就是在不同的view里还是需要做相同的事情,给个日期空间选择例子吧 ...

  5. 利用pscp命令实现linux与windows文件互传

    windows==>linux(单个文件) PrivateKey.ppk(私钥)可以是相对路径或者绝对路径pscp -i D:\PrivateKey.ppk D:\xxx.xx root@123 ...

  6. STM32F407的串口采用DMA收发数据

    源:STM32F407的串口采用DMA收发数据

  7. Neutron网络性能测试与分析(一) CVR

    测试环境:网络节点运行在Intel(R) Xeon(R) CPU E5-2630 v3服务器上,网卡使用intel的万兆卡82599ES 测试仪使用本人基于dpdk编写的程序,基本上可以打满万兆卡,小 ...

  8. InnoDB表要建议用自增列做主键

    InnoDB引擎表是基于B+树的索引组织表(IOT): 每个表都需要有一个聚集索引(clustered index): 所有的行记录都存储在B+树的叶子节点(leaf pages of the tre ...

  9. Nginx访问限速配置方法详解

    开发测试阶段在本地限速模拟公网的环境,方便调试.投入运营会有限制附件下限速度,限制每个用户的访问速度,限制每个IP的链接速度等需求. 配置简单,只需3行,打开"nginx根目录/conf/n ...

  10. mysql、sqlserver数据库常见数据类型对应java中的的类型探究

    由于本次测试表的结构不涉及到主键的自增长,所以mysql.sqlserver建表语句相同: CREATE TABLE testType ( id INT NOT NULL DEFAULT 0, gen ...