Dating with girls(2)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1812    Accepted Submission(s): 505

Problem Description
If you have solved the problem Dating with girls(1).I think you can solve this problem too.This problem is also about dating with girls. Now you are in a maze and the girl you want to date with is also in the maze.If you can find the girl, then you can date with the girl.Else the girl will date with other boys. What a pity! 
The Maze is very strange. There are many stones in the maze. The stone will disappear at time t if t is a multiple of k(2<= k <= 10), on the other time , stones will be still there. 
There are only ‘.’ or ‘#’, ’Y’, ’G’ on the map of the maze. ’.’ indicates the blank which you can move on, ‘#’ indicates stones. ’Y’ indicates the your location. ‘G’ indicates the girl's location . There is only one ‘Y’ and one ‘G’. Every seconds you can move left, right, up or down.
 
Input
The first line contain an integer T. Then T cases followed. Each case begins with three integers r and c (1 <= r , c <= 100), and k(2 <=k <= 10).
The next r line is the map’s description.
 
Output
For each cases, if you can find the girl, output the least time in seconds, else output "Please give me another chance!".
 
Sample Input
1
6 6 2
...Y..
...#..
.#....
...#..
...#..
..#G#.
 
Sample Output
7
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1175 1072 1728 1180 1026 
 
 //15MS    808K    1432 B    G++
/* 题意:
给出一个nm图,问点Y到点G的最少步数,其中每当步数为k的整数倍时障碍物可以通行。 bfs:
比较明显是一道bfs,不过有点小变形,需要一个三维数组来记录步数。 第三维记录模k的余数,
此处可以减低时间复杂度和空间复杂度。避免重复且耗时更多的情况。 */
#include<iostream>
#include<queue>
#define inf 0x7ffffff
using namespace std;
struct node{
int x,y,cnt;
};
char g[][];
int step[][][];
int n,m,k;
int sx,sy,ex,ey;
int mov[][]={,,,,,-,-,};
int bfs()
{
memset(step,-,sizeof(step));
queue<node>Q;
node t={sx,sy,};
Q.push(t);
while(!Q.empty()){
t=Q.front();
Q.pop();
if(t.x==ex && t.y==ey){
return t.cnt;
}
for(int i=;i<;i++){
node tt=t;
tt.cnt++;
tt.x+=mov[i][];
tt.y+=mov[i][];
if(tt.x>=&&tt.x<n && tt.y>=&&tt.y<m){
if(g[tt.x][tt.y]=='#' && tt.cnt%k!=) continue;
if(step[tt.x][tt.y][tt.cnt%k]!=-) continue;
step[tt.x][tt.y][tt.cnt%k]=tt.cnt;
Q.push(tt);
}
}
}
return -;
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
scanf("%s",g[i]);
for(int j=;j<m;j++){
if(g[i][j]=='Y')
sx=i,sy=j;
if(g[i][j]=='G')
ex=i,ey=j;
}
}
int ans=bfs();
if(ans==-) puts("Please give me another chance!");
else printf("%d\n",ans);
}
return ;
}

hdu 2579 Dating with girls(2) (bfs)的更多相关文章

  1. hdu 2579 Dating with girls(2)

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

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

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

  8. 【HDOJ】2579 Dating with girls(2)

    简单BFS. /* 2579 */ #include <iostream> #include <queue> #include <cstdio> #include ...

  9. Dating with girls(1)(二分+map+set)

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

随机推荐

  1. 内置函数SQLCODE和SQLERRM的使用

    由于ORACLE的错信息最大长度是512字节,为了得到完整的错误提示信息,我们可用 SQLERRM 和 SUBSTR 函数一起得到错误提示信息,方便进行错误,特别是如果WHEN OTHERS异常处理器 ...

  2. poj_3641_Pseudoprime numbers

    Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). Th ...

  3. 交换机基础配置之三层交换机实现vlan间通信

    我们以上面的拓扑图做实验,要求为pc1,pc2,pc3配置为vlan10,pc4,pc5,pc6配置为vlan20,pc7,pc8,pc9配置为vlan30 server0和server1配置为vla ...

  4. JQuery制作网页—— 第一章 JavaScript基础

    1. JavaScript(弱类型语言):是一种描述性语言,也是一种基于对象(Object)和事件驱动(Event Driven)的,并具有安全性能的脚本语言. 特点:1.主要用来在HTML页面中添加 ...

  5. 《Redis设计与实现》- 复制

    在分布式系统中为了解决单点问题,通常会把数据复制多个副本部署到其他机器,满足故障恢复和负载均衡灯需求.Redis提供了复制功能,实现了相同数据多个副本,复制功能作是高可用Redis的基础,深入理解复制 ...

  6. yii rbac

    一.简介 什么是rbac ? rbac是就是基于角色的访问控制. yii提供一套基础的底层接口,我们知道,rbac经历好几个阶段,从rbac0到rbac3,从基础的用户.角色.权限,到动态的rbac处 ...

  7. 好用的 Html、CSS、JavaScript 开源项目

    1.极简模块化前端UI框架 Layui 评分:9.3:收藏量:873 授权协议:MIT 开发语言:JavaScript.HTML/CSS 操作系统:跨平台 源码地址:https://gitee.com ...

  8. Python学习之高级特性

    切片 在Python基础篇里,我们知道Python的可序列对象可以通过索引号(下标)来引用对象元素,索引号可以由0开始从左向右依次获取,可以从-1开始由右向左获取.这种方法可以帮助我们依次获取我们想要 ...

  9. ln -s 软链接产生Too many levels of symbolic links错误

    不能使用相对路径, ln -s ./cmake /usr/bin/ 而是要 ln -s /usr/local/bin/cmake /usr/bin/

  10. linux c scanf()小解

    今天学习了新的内容,关于c语言的scanf()函数. scanf()函数,读取指定格式的值赋值给相应变量.空格(‘ ‘),回车('\n'),TAB是分隔符,轻易不会被读取.还有,该函数的返回值是正确读 ...