Dating with girls(2)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1812    Accepted Submission(s): 505

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
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1175 1072 1728 1180 1026 
 
 //15MS    808K    1432 B    G++
/* 题意:
给出一个nm图,问点Y到点G的最少步数,其中每当步数为k的整数倍时障碍物可以通行。 bfs:
比较明显是一道bfs,不过有点小变形,需要一个三维数组来记录步数。 第三维记录模k的余数,
此处可以减低时间复杂度和空间复杂度。避免重复且耗时更多的情况。 */
#include<iostream>
#include<queue>
#define inf 0x7ffffff
using namespace std;
struct node{
int x,y,cnt;
};
char g[][];
int step[][][];
int n,m,k;
int sx,sy,ex,ey;
int mov[][]={,,,,,-,-,};
int bfs()
{
memset(step,-,sizeof(step));
queue<node>Q;
node t={sx,sy,};
Q.push(t);
while(!Q.empty()){
t=Q.front();
Q.pop();
if(t.x==ex && t.y==ey){
return t.cnt;
}
for(int i=;i<;i++){
node tt=t;
tt.cnt++;
tt.x+=mov[i][];
tt.y+=mov[i][];
if(tt.x>=&&tt.x<n && tt.y>=&&tt.y<m){
if(g[tt.x][tt.y]=='#' && tt.cnt%k!=) continue;
if(step[tt.x][tt.y][tt.cnt%k]!=-) continue;
step[tt.x][tt.y][tt.cnt%k]=tt.cnt;
Q.push(tt);
}
}
}
return -;
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
scanf("%s",g[i]);
for(int j=;j<m;j++){
if(g[i][j]=='Y')
sx=i,sy=j;
if(g[i][j]=='G')
ex=i,ey=j;
}
}
int ans=bfs();
if(ans==-) puts("Please give me another chance!");
else printf("%d\n",ans);
}
return ;
}

hdu 2579 Dating with girls(2) (bfs)的更多相关文章

  1. hdu 2579 Dating with girls(2)

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

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

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

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

  5. hdu 2578 Dating with girls(1)

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

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

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

  7. hdu 2578 Dating with girls(1) 满足条件x+y=k的x,y有几组

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

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

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

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

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

随机推荐

  1. iOS网络图片缓存详解

    在开发移动应用的时候比如Android,IOS,因为手机流量.网速.内存等这些因素,当我们的移动应用是针对互联网,并要频繁访问网络的话,对网络优化这块就显得尤为重要了. 比如某个应用要经常显示网络图片 ...

  2. 配置intellij idea中的欢迎页而不使用默认的index.jsp

    在web.xml中添加 <welcome-file-list> <welcome-file>abc.jsp</welcome-file> </welcome- ...

  3. LVS+Keepalived-DR模式负载均衡高可用集群

    LVS+Keepalived DR模式负载均衡+高可用集群架构图 工作原理: Keepalived采用VRRP热备份协议实现Linux服务器的多机热备功能. VRRP,虚拟路由冗余协议,是针对路由器的 ...

  4. HTML语义化的重要性

    语义化标签就是尽量使用有相对应的结构的含义的Html的标签 1.结构更好,更利于搜索引擎的抓取(SEO的优化)和开发人员的维护(可维护性更高,因为结构清晰,so易于阅读). 2.更有利于特殊终端的阅读 ...

  5. 页面刷新 方法总结 JSP刷新

    1) <meta http-equiv="refresh"content="10;url=跳转的页面"> 10表示间隔10秒刷新一次 2) < ...

  6. tcl之控制流-while

  7. [BZOJ1927]星际竞速(费用流)

    Description 题意:给定n个点m条边的无向图,只能从编号小的到编号大的,且要求经过所有点刚好一次,而且可以从任意点瞬移到i号点并花费代价Ai,求最小代价. n<=800,m<=1 ...

  8. rpm、yum命令

    一.rpm命令 挂载光盘文件到/media目录: 进去/media目录下的Packages目录: 查看系统已安装的所有rpm包: 查看系统是否安装dhcp软件包: 安装dhcp软件包: 查看dhcp软 ...

  9. Java集合——LinkedHashMap源码详解

    个KV.LinkedHashMap不仅像HashMap那样对其进行基于哈希表和单链表的Entry数组+ next链表的存储方式,而且还结合了LinkedList的优点,为每个Entry节点增加了前驱和 ...

  10. Kafka安装和常用操作命令

    Kafka安装: 下载kafka_2.10-0.8.2.1 1.关闭防火墙 2.修改配置文件  server.properties broker.id=1log.dirs= /usr/kafka_2. ...