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. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  2. iOS 应用开发入门指南

    前言:http://www.guomii.com/posts/20250安装工具:http://www.guomii.com/posts/20255工具:http://www.guomii.com/p ...

  3. Windows Phone - 按钮/button 控件

    System.Windows.Controls.Button   button控件一.button控件的各种样式的展示可以通过 …… 来给控件定义公共的样式调用样式的方法:在Button控件上添加样式 ...

  4. QT与openCV,与PCL结合!

    (1):详解QT多媒体框架:给予视频播放器 原文链接:http://mobile.51cto.com/symbian-271123.htm 对于使用主框架的QT程序,实现Qimage的转换可借鉴下面程 ...

  5. UVa340(Master-Mind Hints)未完成

    #include<stdio.h> int main() { int num,a[100],i,j,b[100]; while(scanf("%d",&num) ...

  6. css 添加阴影

    添加阴影,分为内阴影和外阴影. inset:内阴影. 不写默认外阴影. box-shadow: 水平位移  垂直位移  模糊半径 #box-shadow{ -moz-box-shadow:5px 5p ...

  7. Kattis - iBoard

    iBoard After years of success with a single-button mouse, a well known computer company has decided ...

  8. centos7 选定默认启动内核,及删除无用内核

    #使用cat /boot/grub2/grub.cfg |grep menuentry 查看系统可用内核 [root@bigapp-slave27 ~]# cat /boot/grub2/grub.c ...

  9. Tab 切换效果

    今天写的两个小效果都是为了测试我写的单参函数,结果还是有点成功的~~此处是不是想发表情包! Tab效果很简单,这里我就不赘述了,直接上代码: html代码: <div class="c ...

  10. 计蒜客 宝藏 (状压DP)

    链接 : Here! 思路 : 状压DP. 开始想直接爆搜, T掉了, 然后就采用了状压DP的方法来做. 定义$f[S]$为集合$S$的最小代价, $dis[i]$则记录第$i$个点的"深度 ...