Dating with girls(2)

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

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

 //2016.8.4
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring> using namespace std; struct node
{
int x, y, sec;
};
char m[][];
int vis[][][];
int c, r, k, T, sx, sy, ex, ey;
int dx[] = {, , -, };
int dy[] = {, , , -}; void bfs()
{
node start;
start.x = sx; start.y = sy; start.sec = ;
queue<node> q;
q.push(start);
vis[sx][sy][] = ;
while(!q.empty())
{
node tmp = q.front();
node in;
q.pop();
for(int i = ; i < ; i++)
{
int nx = tmp.x+dx[i];
int ny = tmp.y+dy[i];
in.x = nx; in.y = ny; in.sec = tmp.sec+;
if(nx>=&&nx<r&&ny>=&&ny<c&&!vis[nx][ny][in.sec%k])
{
if(in.x == ex && in.y == ey)
{
cout<<in.sec<<endl;
return;
}
if((tmp.sec+)%k== || m[nx][ny]=='.' || m[nx][ny]=='Y')
{
q.push(in);
vis[nx][ny][in.sec%k] = ;
}
}
}
}
cout<<"Please give me another chance!"<<endl;
} int main()
{
cin >> T;
while(T--)
{
scanf("%d%d%d", &r, &c, &k);
for(int i = ; i < r; i++)
{
getchar();
for(int j = ; j < c; j++)
{
scanf("%c", &m[i][j]);
if(m[i][j] == 'Y')
{
sx = i;
sy = j;
}
if(m[i][j] == 'G')
{
ex = i;
ey = j;
}
}
}
memset(vis, , sizeof(vis));
bfs();
} return ;
}

参考:http://blog.csdn.net/mengxiang000000/article/details/51066586

HDU2579的更多相关文章

  1. hdu2579之BFS

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

  2. HDU2579(bfs迷宫)

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

随机推荐

  1. 控制textbook输入字符

    在KeyPress事件中假如如下代码此实例表示可输入数字退格和“.”. 具体字符KeyChar见连接 http://www.cnblogs.com/linji/archive/2012/10/24/2 ...

  2. source command not found in sh shell解决办法

    在Ubuntu系统中执行脚本的时候突然出现错误"source command not found in sh shell" 这个其实在Ubuntu 当中 执行脚本默认的使用的是da ...

  3. /bin/sh 与 /bin/bash 的区别

    /bin/sh 与 /bin/bash 的区别,用 : 截取字符串不是POSIX 标准的. 区别 sh 一般设成 bash 的软链 (symlink) ls -l /bin/sh lrwxrwxrwx ...

  4. MyBatis 3 中使用存储过程

    转:http://zachary-guo.iteye.com/blog/1756689 Mybats 是 iBatis 被 Google 收购后重新命名的一个工程,当然也做了大量的升级.iBatis ...

  5. 【iScroll源码学习01】准备阶段 - 叶小钗

    [iScroll源码学习01]准备阶段 - 叶小钗 时间 2013-12-29 18:41:00 博客园-原创精华区 原文  http://www.cnblogs.com/yexiaochai/p/3 ...

  6. UVA 10518 How Many Calls?

    题意:一个递推式第n项%b是多少. 递推式: 构造矩阵: #include<cstdio> #include<cstring> #include<cmath> #i ...

  7. oracle 11g odbc连接串及配置

    首先先安装HA-Instant Client-v11.2.0.3.0-x86.rar 下载地址: ftp://hhdown:2-2@58.23.131.52/download/HA-Instant%2 ...

  8. JS利用短路原理简写if语句

    看GoogleDoodle-Dance的源代码,学习到一个小知识——简写if语句. 几乎所有语言中||和&&都遵循“短路”原理,如&&中第一个表达式为假就不会去处理第二 ...

  9. php连接mysql数据库(新浪云SAE)

    新浪云提供了免费的创建服务器端应用的服务.网址为:https://www.sinacloud.com/ 在上面创建好应用,然后在本地使用记事本编写应用的代码如下: <?php echo &quo ...

  10. IOS开发-UI学习-UIFont,字体设置及批量创建控件

    在IOS 中,使用[UIFont familyNames]这个方法获取72种系统字体. 使用[UIFont fontWithName:@"Zapfino" size:18]这个方法 ...