HDU2579
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
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 next r line is the map’s description.
Output
Sample Input
Sample Output
//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的更多相关文章
- hdu2579之BFS
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU2579(bfs迷宫)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- 水流(water)
水流(water) 题目描述 全球气候变暖,小镇A面临水灾,于是你必须买一些泵把水抽走.泵的抽水能力可以认为是无穷大,但你必须把泵放在合适的位置,从而能使所有的水能流到泵里.小镇可以认为是N×M的矩阵 ...
- Java网络通信——XML和JSON
XML(Extensible Markup Language) 定义:一种可扩展的标记性语言 XML有丰富的编码工具,比如Dom4j.JDom等. JSON(JavaScript Object Not ...
- SQL truncate 、delete与drop区别
SQL truncate .delete与drop区别 相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句 ...
- html-div-css
用CSS实现拉动滚动条时固定网页背景不动 body{ background-image: url(./inc/bgbk.jpg); background-attachm ...
- (译)Windsor入门教程---第一部分 获取Windsor
原文:http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx ...
- (简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。
Description Your boss once had got many copies of a treasure map. Unfortunately, all the copies are ...
- mysql基础-- 一条请求执行多条SQL语句
最近做一个数据库初始化工具的时候发现了这个问题,就是在一个Statement中执行一条SQL语句的时候可以正确执行,如果同时执行多条,就会报SQL语法错误,伤透了脑筋. 经过网上查找,发现有两种解决办 ...
- input的onchange事件实际触发条件与解决方法
input中onchange事件已经属于元老级别了,并且现在同onclick一样使用频率很高,然而onchange的机制实际上有很多童鞋并不清楚,我们通过实例来分析这个事件的特征. 触发onchang ...
- Android SQLITE数据类型
2011-6-24 15:14:00来源:Sql SQLITE数据类型 SQLite与其他常见的DBMS的最大不同是它对数据类型的支持.其他常见的DBMS通常支持强类型的数据,也就是每一列的类型都 ...
- 22、手把手教你Extjs5(二十二)模块Form的自定义的设计[1]
下面开始设计和完成一个简单的Form的自定义过程.先准备数据,在ModuleModel.js中的data属性下面,加入自定义Form的参数定义,下面的代码中定义了一个新的属性tf_formScheme ...