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 ...
随机推荐
- 控制textbook输入字符
在KeyPress事件中假如如下代码此实例表示可输入数字退格和“.”. 具体字符KeyChar见连接 http://www.cnblogs.com/linji/archive/2012/10/24/2 ...
- source command not found in sh shell解决办法
在Ubuntu系统中执行脚本的时候突然出现错误"source command not found in sh shell" 这个其实在Ubuntu 当中 执行脚本默认的使用的是da ...
- /bin/sh 与 /bin/bash 的区别
/bin/sh 与 /bin/bash 的区别,用 : 截取字符串不是POSIX 标准的. 区别 sh 一般设成 bash 的软链 (symlink) ls -l /bin/sh lrwxrwxrwx ...
- MyBatis 3 中使用存储过程
转:http://zachary-guo.iteye.com/blog/1756689 Mybats 是 iBatis 被 Google 收购后重新命名的一个工程,当然也做了大量的升级.iBatis ...
- 【iScroll源码学习01】准备阶段 - 叶小钗
[iScroll源码学习01]准备阶段 - 叶小钗 时间 2013-12-29 18:41:00 博客园-原创精华区 原文 http://www.cnblogs.com/yexiaochai/p/3 ...
- UVA 10518 How Many Calls?
题意:一个递推式第n项%b是多少. 递推式: 构造矩阵: #include<cstdio> #include<cstring> #include<cmath> #i ...
- 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 ...
- JS利用短路原理简写if语句
看GoogleDoodle-Dance的源代码,学习到一个小知识——简写if语句. 几乎所有语言中||和&&都遵循“短路”原理,如&&中第一个表达式为假就不会去处理第二 ...
- php连接mysql数据库(新浪云SAE)
新浪云提供了免费的创建服务器端应用的服务.网址为:https://www.sinacloud.com/ 在上面创建好应用,然后在本地使用记事本编写应用的代码如下: <?php echo &quo ...
- IOS开发-UI学习-UIFont,字体设置及批量创建控件
在IOS 中,使用[UIFont familyNames]这个方法获取72种系统字体. 使用[UIFont fontWithName:@"Zapfino" size:18]这个方法 ...