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. SilverLight Q&A

    1.在学校prism,Unity框架的时候,遇到的问题“The IModuleCatalog is required and cannot be null in order to initialize ...

  2. Monad的重点

    Monad是非常强有力的概念,在介绍Monad是什么和如何工作的之前,我们应该先确认Monad能解决什么问题.Monad是各种编程问题的的 meta solution,它不是某种特定问题的解决方案,我 ...

  3. 应用MVP模式对遗留代码进行重构

    AV(Autonomous View)自治视图 在面向终端用户的应用中,都需要一个可视化的UI来与用户交互.这个UI称为View视图. 在早期,我们习惯将所有前台的逻辑,与视图揉在一起,称为AV自治视 ...

  4. Android学习——Button填充颜色及实现圆角

    在drawable下新建文件夹bt_shape.xml,如下: <?xml version="1.0" encoding="utf-8"?> < ...

  5. draw9patch在SDK->tools找不到,在Android Studio点击图片没找到draw9patch

    draw9patch在SDK->tools找不到,在Android Studio点击图片没找到draw9patch 第一个问题: Google把draw9patch集成在Android Stud ...

  6. 【Oracle】DBMS_STATS.GATHER_TABLE_STATS分析表

    表分析,简单的说,就是收集表和索引的信息,CBO根据这些信息决定SQL最佳的执行路径.通过对表的分析,可以产生一些统计信息,通过这些信息oracle的优化程序可以进行优化. 语法: DBMS_STAT ...

  7. Javascript关于JSON集合的几种循环方法

    /** * 根据json数据生成option树形控件 * 如果有children节点则自动生成树形数据 * @param {JSON} data * @param {int} n 节点深度 * @pa ...

  8. java加密解密算法位运算

    一.实例说明 本实例通过位运算的异或运算符 “ ^ ” 把字符串与一个指定的值进行异或运算,从而改变每个字符串中字符的值,这样就可以得到一个加密后的字符串.当把加密后的字符串作为程序输入内容,异或运算 ...

  9. day09网络编程

    一 操作系统基础 操作系统:(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才 ...

  10. U盘启动盘安装Mac OS

    1.下载macOS High Sierra正式版 http://www.pc6.com/mac/gj_715_1.htm http://www.pc6.com/mac/518996.html 下载ma ...