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 ...
随机推荐
- 二维小波包重构wprec2\wprcoef
clc,clear all,close all; load woman; t=wpdec2(X,2,'haar');%小波包2层分解 r_X=wprec2(t);%重构小波包 r_X10=wprcoe ...
- JVM问题诊断常用命令:jinfo,jmap,jstack
1.jinfo 描述:输出给定 java 进程所有的配置信息.包括 java 系统属性和 jvm 命令行标记等. 用法: jinfo [ option ] pid jinfo [ option ] e ...
- strings
3.1.1.1 计算列表中的字符串数目 使用Count属性可计算列表中的字符串数目.Count是只读属性,用以指示列表中字符串列表数目.因为字符串列表是以零开始索引,因而Count比列表的最大索引数大 ...
- app 一些常用的
发短信 :sms:10086 打电话:tel:10086 1.-webkit-tap-highlight-color:rgba(255,255,255,0)可以同时屏蔽ios和android下点击元素 ...
- java并发编程框架 Executor ExecutorService invokeall
首先介绍两个重要的接口,Executor和ExecutorService,定义如下: public interface Executor { void execute(Runnable command ...
- [转]Publishing and Running ASP.NET Core Applications with IIS
本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...
- apt-get 总结2
本文列举了常用的APT命令参数: apt-cache search package 搜索软件包 apt-cache show package 获取包的相关信息,如说明.大小.版本等 sudo apt ...
- java多维数组
int a[][][] = {{{1,2},{1,2}},{{1,2},{1,2}}}; int b[][][] = new int[][][]{{{1,2},{1,2}},{{1,2},{1,2}} ...
- js第一天 innerHTML和value 的区别
innerHTML在JS是双向功能:获取对象的内容 或 向对象插入内容:如:<div id="aa">这是内容</div> ,我们可以通过 document ...
- ebtables
ebtables是以太网桥防火墙,以太网工作在数据链路层,ebtables过滤数据链路层包.2.6内核内置了ebtables,要使用它必须先按装她的用户空间工具(ebtables-V2.0.6),安装 ...