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. javascript入门笔记2-window

    1.JavaScript-输出内容(document.write) <script type="text/javascript"> document.write(&qu ...

  2. js一键复制到剪切板

    <div id='demo'>我就是被复制的内容<span>点击复制<span></div> $('#demo').on('click','span', ...

  3. JS - 给String.prototype添加replaceAll方法

    String.prototype.replaceAll = function (targetStr, newStr) {  var sourceStr = this.valueOf();  while ...

  4. oracle下表空间、用户创建以及用户授权流程

    Oracle,表空间的建立.用户创建以及用户授权 主要是以下几步,挑选需要的指令即可: # 首先以scott用户作为sysdba登陆 conn scott/tiger as sysdba #创建用户 ...

  5. Lucene实战

    导包

  6. 如何理解MVVM?

    随着前端页面越来越复杂,用户对于交互性要求也越来越高,MVVM模型应运而生. MVVM最早由微软提出来,它借鉴了桌面应用程序的MVC思想,在前端页面中,把Model用纯JavaScript对象表示,V ...

  7. Nginx 配置继承模型

    要了解nginx的继承模型,首先需要知道nginx使用多个配置块进行操作.在nginx中,这样的块被称为上下文,例如,放置在服务器上下文中的配置指令驻留在server { }块中,就像放置在http上 ...

  8. python之微信好友统计信息

    需要安装库:wxpy 代码如下: from wxpy import Bot,Tuling,embed,ensure_one bot = Bot(cache_path=True) #获取好友信息 bot ...

  9. Sublime package control错误:There are no packages available for installation

    查了很多资料都没有解决. 改host---无效 复制一个文件的什么的,我看到版本比我的旧,就没有用 终于最后一个解决了.最终解决方案 解决: 更新下Package Control就好了: prefer ...

  10. Android 本应用数据清除管理器DataCleanManager

    1.整体分析 1.1.源代码先给出了,可以直接Copy. /** * 本应用数据清除管理器 */ public class DataCleanManager { /** * * 清除本应用内部缓存(/ ...