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 ...
随机推荐
- strpos 返回0时 ,比较false 不能加单引号
$a = 'a.approve'; $num = strpos($a,'a.admin'); if(strpos($a,'a.approve') !== 'false'){ //不能加单引号.变字符 ...
- wep密钥的长度
理论上,WEP可以搭配任意长度的密钥,因为RC4并未要求非得使用特定长度的密钥. 不过,大多数产品均支持一种或两种长度的密钥.唯一出现在标准中的密钥长度时64位的WEP种子(seed),其中40位是两 ...
- HDU 1509 Windows Message Queue(队列)
题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...
- servlet规范核心类图
作为新手在写servlet时很多时候忘记类与类之间的关系,找到这张图就瞬间清晰了,这比看API要舒服很多.
- LeetCode OJ 54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- js与jquery实时监听输入框值变化方法
本文实例讲述了js与jquery实时监听输入框值的oninput与onpropertychange方法.分享给大家供大家参考.具体如下: 最近做过一个项目,需求是下拉框里自动匹配关键字,具体细节是实时 ...
- 自定义alert和confirm
var common = {}; common.showAlert = function (msg) { var html = "<div id='dialog_alert' clas ...
- Merge Into 用法
从一个数据库的一张表同步数据到另外一个数据库的一张表,同步的数据不是insert就是update. 一般做法是先判断当前数据在另外一张表存不存在,存在则更新,不存在则插入.需要一次查询判断:exist ...
- js继承实现
JS实现继承可以分为:对象冒充和原型链继承 其中对象冒充又包括:临时变量,call 和 apply 临时变量方法: function Person(name,sex){ this.name = nam ...
- Nginx访问限速配置方法详解
开发测试阶段在本地限速模拟公网的环境,方便调试.投入运营会有限制附件下限速度,限制每个用户的访问速度,限制每个IP的链接速度等需求. 配置简单,只需3行,打开"nginx根目录/conf/n ...