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 ...
随机推荐
- CodeForces 609A USB Flash Drives
水题 #include<cstdio> #include<cmath> #include<algorithm> using namespace std; +; in ...
- 微信小程序实例教程(二)
第五章:微信小程序名片夹详情页开发 今天加了新干货!除了开发日志本身,还回答了一些朋友的问题. 闲话不多说,先看下「名片盒」详情页的效果图: 备注下大致需求:顶部背后是轮播图,二维码按钮弹出模态框信息 ...
- [python]小练习__创建你自己的命令行 地址簿 程序
创建你自己的命令行 地址簿 程序. 在这个程序中,你可以添加.修改.删除和搜索你的联系人(朋友.家人和同事等等)以及它们的信息(诸如电子邮件地址和/或电话号码). 这些详细信息应该被保存下来以便以后提 ...
- Laravel Eloquent get获取空的数据问题
在用laravel框架来获取数据,若数据不存在时,以为会返回空,其实不是的,其实是一个 collection 值,会返回如下: object(Illuminate\Database\Eloquent\ ...
- (简单) POJ 1426 Find The Multiple,BFS+同余。
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- Android之布局大全
Android布局方式可以归类为ViewGroup的5个类别,即ViewGroup的5个直接子类.其它的一些布局都扩展自这5个类. 上结构图: 转自:http://www.cnblogs.com/de ...
- iOS8 UISearchViewController搜索功能讲解 分类: ios技术 2015-07-14 10:23 76人阅读 评论(0) 收藏
在iOS8以前我们实现搜索功能需要用到UISearchbar和UISearchDisplayController, 在iOS8之后呢, UISearchController配合UITableView的 ...
- js 设置导航固定
<div id="nav"> .... </div> function Add_Data() { var top = $("#header-nav ...
- jenkins 构建时,取消构建测试类
如图 点击配置,添加clean install -Dmaven.test.skip=true 保存即可
- python 开发者 精品
当 Python 和 R 遇上北京二手房 http://mp.weixin.qq.com/s?timestamp=1473262097&src=3&ver=1&signatur ...