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存储方式MyISAM 和 InnoDB的区别
MyISAM 和 InnoDB 讲解: InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级 ...
- MySQL分库分表的技巧
分表是分散数据库压力的好方法. 分表,最直白的意思,就是将一个表结构分为多个表,然后,可以再同一个库里,也可以放到不同的库. 当然,首先要知道什么情况下,才需要分表.个人觉得单表记录条数达到百万到千万 ...
- client的使用
document.documentElement.clientHeight = 464 // 指窗口的可见高度的大小 document.body.clientHeight = 1577 // 指窗口的 ...
- hibernate课程 初探单表映射2-6 session详解(下)
本节主要内容: 1 介绍了getCurrentSession和opensession的区别 2 demo:通过打印比较两个session是否相同,验证两个session是否是同一session 3 d ...
- c语言数据结构:用标志位实现循环队列
#include<stdio.h> #include<stdlib.h> #define MAXSIZE 10//定义队列长度 ;//定义标志位 typedef struct ...
- IIS 处理高并发
1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Settings Queu ...
- SQL中如何避免书签查找
1.使用聚集索引 对于聚集索引,索引的叶子页面和表的数据页面相同.因此,当读取聚集索引键列的值时,数据引擎可以读取其他列的值而不需要任何导航.例如前面的区间数据查询的操作,SQLServer通过B树结 ...
- Android商城开发系列(十四)—— 设置监听RecyclerView的位置
在前面的博客中有讲到过点击一个图片按钮控制RecyclerView的滚动到顶部位置的效果,但是那个图片按钮一直处在一个显示的状态,今天我们来改造一下那个地方,我们要实现的效果是:一开始打开的时候看不到 ...
- c++ vector & 二维数组 & MessageBox
vector: https://www.cnblogs.com/mr-wid/archive/2013/01/22/2871105.html c++ 二维数组: int **p; p = new in ...
- Aizu 0525 Osenbei(状压+贪心)
题意:翻煎饼,只能横着翻或者竖着翻.问最多有多少朝上? 行只有10,所以枚举一下2^10的状态,每列取0或1中最大的一个. 在枚举外面把饼翻好,枚举里面指针指一下就好.(位运算或bitset乱搞 #i ...