Dating with girls(2)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2691    Accepted Submission(s): 752

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

#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
//三维标记 ,当前的时间与t取余,到达"#"的时间只有t种,
//如果这几种都不行,那这条路就废了
char map[110][110];
int a[110][110][12];
int m,n,t;
int sx,sy;
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
struct node
{
int x,y,step;
friend bool operator < (node s1 ,node s2)
{
return s1.step>s2.step;
}
}p,temp;
void bfs()
{
memset(a,0,sizeof(a));
queue<node>q;
p.x=sx,p.y=sy;
p.step=0;
q.push(p);
a[sx][sy][0]=1;
while(!q.empty())
{
p=q.front();
q.pop();
if(map[p.x][p.y]=='G')
{
printf("%d\n",p.step);
return ;
}
for(int i=0;i<4;i++)
{
temp.x=p.x+dx[i];
temp.y=p.y+dy[i];
temp.step=p.step+1;
int d=temp.step%t;
if(temp.x<0||temp.x>=n||temp.y<0||temp.y>=m||a[temp.x][temp.y][d])
continue;
a[temp.x][temp.y][d]=1;
if(map[temp.x][temp.y]=='#'&&d)
continue;
q.push(temp);
}
}
printf("Please give me another chance!\n");
}
int main()
{
int s;
scanf("%d",&s);
while(s--)
{
scanf("%d%d%d",&n,&m,&t);
for(int i=0;i<n;i++)
{
scanf("%s",map[i]);
for(int j=0;j<m;j++)
{
if(map[i][j]=='Y')
sx=i,sy=j;
}
}
bfs();
}
return 0;
}

 

hdoj--2579--Dating with girls(2)(搜索+三维标记)的更多相关文章

  1. hdoj 2579 Dating with girls(2)【三重数组标记去重】

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. hdu 2579 Dating with girls(2)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...

  3. 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 ...

  4. 【HDOJ】2579 Dating with girls(2)

    简单BFS. /* 2579 */ #include <iostream> #include <queue> #include <cstdio> #include ...

  5. 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 ...

  6. 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 ...

  7. hdu 2578 Dating with girls(1)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...

  8. Dating with girls(1)(二分+map+set)

    Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. 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+ ...

随机推荐

  1. 从Oracle同步数据到SQLServer——大小写敏感设置

    Oracle默认是大小写敏感,而SQLServer默认大小写不敏感, 尤其是涉及主键字段时,注意请提前设置SQLServer对应的数据库表为大小写敏感,不然会报主键冲突的错误. 设置表内大小写敏感 A ...

  2. 错误:the apk for your currently selected variant(app-release-unsigned.apk)is not signed.Please specity a signing configuration for this variant(release)

    1:导入android studio project 时总会出现运行处一个红色叉号,这里可以点击选择叉号上面显示的Edit Configurations 查看右下角的错误警告信息.: 2:记录错误: ...

  3. 得到Xml中 元素的值

    <?xml version="1.0" encoding="utf-8" ?><Response service="RouteSer ...

  4. JavaScript Cookies使用

    Cookie 是个存储在客户端(浏览器)记录信息确定用户身份的小文本文件,可以用来跟踪用户当前登陆状态和用户浏览页面的次数,记录用户输入的文本信息,也可以在页面间传递变量,记录用户一些行为. 当浏览器 ...

  5. AI:从游戏引擎--到AI

    原文链接:http://blog.csdn.net/left_la/article/details/6358911#t9 这是我在Gameres上看到的一篇文章,文章很长,全文分为11个部分,看后感觉 ...

  6. 我的C++笔记(语句基本结构)

    #include <iostream> using namespace std; int main() { unsigned char c1=24; int year; bool isLe ...

  7. 工欲善其事必先利其器之windows篇

    Windows是我们最常用的系统,下面就让我们重新认识一下Windows有哪些可以让我们提高工作效率的快捷键以及部分技巧,,以及在外行看来可以看起来逼格高的技巧! 1.Windows最实用,最常用的快 ...

  8. ReactiveX

    http://reactivex.io The real power comes with the “reactive extensions” (hence “ReactiveX”) — operat ...

  9. spring4+hibernate4+struts2环境搭建

    tomact配置请查看下面的文章 javaEE_maven_struts2_tomcat_first http://www.cnblogs.com/luotuoke/p/4543686.html po ...

  10. 通过nvm 切换 npm 版本

    通过 nvm-windows 更新 npm 1.先安装 nvm-windows .成功后可在命令窗口 输入nvm 查看到 nvm的版本号. 2..在命令窗口输入 nvm list,查看当前使用的 no ...