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. 水流(water)

    水流(water) 题目描述 全球气候变暖,小镇A面临水灾,于是你必须买一些泵把水抽走.泵的抽水能力可以认为是无穷大,但你必须把泵放在合适的位置,从而能使所有的水能流到泵里.小镇可以认为是N×M的矩阵 ...

  2. Java网络通信——XML和JSON

    XML(Extensible Markup Language) 定义:一种可扩展的标记性语言 XML有丰富的编码工具,比如Dom4j.JDom等. JSON(JavaScript Object Not ...

  3. SQL truncate 、delete与drop区别

    SQL truncate .delete与drop区别 相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句 ...

  4. html-div-css

    用CSS实现拉动滚动条时固定网页背景不动   body{        background-image: url(./inc/bgbk.jpg);        background-attachm ...

  5. (译)Windsor入门教程---第一部分 获取Windsor

    原文:http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx ...

  6. (简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。

    Description Your boss once had got many copies of a treasure map. Unfortunately, all the copies are ...

  7. mysql基础-- 一条请求执行多条SQL语句

    最近做一个数据库初始化工具的时候发现了这个问题,就是在一个Statement中执行一条SQL语句的时候可以正确执行,如果同时执行多条,就会报SQL语法错误,伤透了脑筋. 经过网上查找,发现有两种解决办 ...

  8. input的onchange事件实际触发条件与解决方法

    input中onchange事件已经属于元老级别了,并且现在同onclick一样使用频率很高,然而onchange的机制实际上有很多童鞋并不清楚,我们通过实例来分析这个事件的特征. 触发onchang ...

  9. Android SQLITE数据类型

    2011-6-24 15:14:00来源:Sql   SQLITE数据类型 SQLite与其他常见的DBMS的最大不同是它对数据类型的支持.其他常见的DBMS通常支持强类型的数据,也就是每一列的类型都 ...

  10. 22、手把手教你Extjs5(二十二)模块Form的自定义的设计[1]

    下面开始设计和完成一个简单的Form的自定义过程.先准备数据,在ModuleModel.js中的data属性下面,加入自定义Form的参数定义,下面的代码中定义了一个新的属性tf_formScheme ...