BFS:HDU2597-Dating with girls(2) (分时间标记状态)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1418 Accepted Submission(s): 393
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
Source
HDU 2009-5 Programming Contest
Recommend
lcy
#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int k,n,m;
char maps[maxn][maxn];
int dir[4][2] = {1,0,0,1,-1,0,0,-1};
bool vis[maxn][maxn][15],flag;//三维数组第三维为时间的标记
struct node
{
int x,y;
int step;
} now,Next; bool check(int x,int y)
{
if(x<0 || y<0 || x>=n || y>=m)
return false;
else
return true;
} void pre_maps()
{
now.x = -1;
now.y = -1;
memset(maps,0,sizeof(maps));
scanf("%d%d%d",&n,&m,&k);
for(int i=0; i<n; i++)
scanf("%s",maps[i]);
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
if(maps[i][j] == 'Y')
{
now.x = i;
now.y = j;
now.step = 0;
return ;
}
}
} void bfs()
{
queue <node> qu;
qu.push(now);
memset(vis,0,sizeof(vis));
vis[now.x][now.y][now.step%k] = 1;
while(!qu.empty())
{
now = qu.front();
if(maps[now.x][now.y] == 'G')
{
printf("%d\n",now.step);
flag = true;
return ;
}
qu.pop();
Next.step = now.step + 1;
for(int i=0; i<4; i++)
{
Next.x = now.x + dir[i][0];
Next.y = now.y + dir[i][1];
if(check(Next.x,Next.y))
{
if((maps[Next.x][Next.y] != '#' || !(Next.step%k)) && !vis[Next.x][Next.y][Next.step%k])
{
qu.push(Next);
vis[Next.x][Next.y][Next.step%k] = 1;
}
}
}
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
flag = false;
pre_maps();
if(now.x == -1 && now.y == -1)
{
printf("Please give me another chance!\n");
continue;
}
bfs();
if(!flag)
printf("Please give me another chance!\n");
}
}
BFS:HDU2597-Dating with girls(2) (分时间标记状态)的更多相关文章
- hdu 2579 Dating with girls(2) (bfs)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2579 Dating with girls(2)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- hdu 2578 Dating with girls(1)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- Dating with girls(1)(二分+map+set)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2578 Dating with girls(1) (hash)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2578 Dating with girls(1) [补7-26]
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 3784 继续xxx定律 & HDU 2578 Dating with girls(1)
HDU 3784 继续xxx定律 HDU 2578 Dating with girls(1) 做3748之前要先做xxx定律 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ ...
随机推荐
- MySQL三种存储引擎总结
MySQL三种存储引擎 MyISAM.InnoDB.MEMORY 1.MyISAM MyISAM,3.23.34a前的默认存储引擎. 优缺点 优点 在于占用空间小,处理速度快. 缺点 不支持事务的完整 ...
- 解决pyhton aiohttp ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
解决pyhton aiohttp ssl:证书报错问题, 错误信息> Cannot connect to host oapi.dingtalk.com:443 ssl:None [[SSL: C ...
- 转---JS 获取鼠标左右键
原文:http://blog.csdn.net/mine3333/article/details/7291557 function test() { alert(event.x+" &quo ...
- 微信小程序:从本地相册选择图片或使用相机拍照。
wx.chooseImage(OBJECT) 从本地相册选择图片或使用相机拍照. OBJECT参数说明: 示例代码: wx.chooseImage({ count: 1, // 默认9 sizeTyp ...
- 一些C/C++中的函数
项目中使用到的C/C++中的一些函数,记录下来加以理解和掌握. 1.memset( ) memset是计算机中C/C++语言函数.将s所指向的某一块内存中的前n个 字节的内容全部设置为ch指定的ASC ...
- Flash图表控件FusionCharts调整图表百分比大小
用户可以为图表的宽度和高度设置百分比值,用来替代绝对的像素值. 以百分比的方式调整图表,首先需要更新HTML代码,如下所示: <div id="chartContainer" ...
- RxJava 1升级到RxJava 2过程中踩过的一些“坑”
RxJava2介绍 RxJava2 发布已经有一段时间了,是对 RxJava 的一次重大的升级,由于我的一个库cv4j使用了 RxJava2 来尝鲜,但是 RxJava2 跟 RxJava1 是不能同 ...
- 腾讯云服务器CVM购买详细过程 选择我们需要的腾讯云服务器
腾讯云服务商有云服务器.云数据库.CDN.云存储等产品,其中较多的用户会选择腾讯云服务器,因为用途比较广泛,比如用来软件的运行以及网站建设,如今一般都是用云服务器,而不是用虚拟主机,毕竟虚拟主机的性价 ...
- JQuery笔录
1.jQuery 的 hide() 函数,隐藏了 HTML 文档中所有的 <p> 元素.<script type="text/javascript">$(d ...
- 20.JSON
JSON是javascript的一个子集,利用js中的一些儿模式来表示结构化数据.不是只有javascript才使用JSON,JSON是一种数据格式,很多编程语言都有针对JSON的解析器和序列化器. ...