hdu 2579 Dating with girls(2)
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=2579
Dating with girls(2)
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 \leq r , c \leq 100)$, and $k \ (2 \leq k \leq 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
bfs。。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::pair;
using std::queue;
using std::vector;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
const int INF = ~0u >> ;
typedef unsigned long long ull;
char maze[N][N];
bool vis[N][N][];
int r, c, k, Sx, Sy, Dx, Dy;
const int dx[] = { -, , , }, dy[] = { , , -, };
struct Node {
int x, y, s;
Node(int i = , int j = , int k = ) :x(i), y(j), s(k) {}
};
queue<Node> que;
void bfs() {
cls(vis, );
while (!que.empty()) que.pop();
que.push(Node(Sx, Sy, ));
vis[Sx][Sy][] = ;
while (!que.empty()) {
Node tp = que.front(); que.pop();
if (tp.x == Dx && tp.y == Dy) { printf("%d\n", tp.s); return; }
rep(i, ) {
int nx = dx[i] + tp.x, ny = dy[i] + tp.y, ns = tp.s + ;
if (nx < || nx >= r || ny < || ny >= c || vis[nx][ny][ns % k]) continue;
if (maze[nx][ny] == '#' && ns % k != ) continue;
vis[nx][ny][ns % k] = ;
que.push(Node(nx, ny, ns));
}
}
puts("Please give me another chance!");
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) {
scanf("%d %d %d", &r, &c, &k);
rep(i, r) {
scanf("%s", maze[i]);
rep(j, c) {
if (maze[i][j] == 'Y') Sx = i, Sy = j;
else if (maze[i][j] == 'G') Dx = i, Dy = j;
}
}
bfs();
}
return ;
}
hdu 2579 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 ...
- 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+ ...
- 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 2578 Dating with girls(1)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- 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 ...
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 【HDOJ】2579 Dating with girls(2)
简单BFS. /* 2579 */ #include <iostream> #include <queue> #include <cstdio> #include ...
- Dating with girls(1)(二分+map+set)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- DragonBone在FlashDevelop编译
http://dragonbones.github.io/ dragonbones是一个强大的骨骼动画编辑器,基于Starling,用AS3语言编写,可以导出骨骼动画数据供其他程序使用. 下面来讲一下 ...
- 【转】Java的接口和抽象类的区别
1. 抽象类和接口的区别 所谓抽象类是用来表征我们在对问题领域进行分析.设计中得出的抽象概念,是对一系列看上去不同,但是本质上相同的具体概念的抽象:所谓接口,相当于电源插座,可插入构件相当于 ...
- Ajax-(get/post/jQuery方式请求)
< !DOCTYPE html > < html xmlns = "http://www.w3.org/1999/xhtml" > < head &g ...
- MySQL:MySQL和SQL Server的区别
导读:接下来的网上商城的项目,需要用到MySQL数据库了.这个对于我来说,是一个新接触的东西,按照惯例,在刚开始学习一个东西的时候,先从宏观上去了解它.本篇博客,先介绍SQL Server的基本内容, ...
- jqmobi 转换语言
当第一次打开APP时,检测手机默认的语言,设置APP的语言跟手机默认一样:当点击了APP里面的设置语言的按钮,存储当前设置的语言 :关闭APP:再一次打开APP时,检测存储在APP里面的语言,转换语言 ...
- CSS 之 Opacity多浏览器透明度兼容处理
用来设定元素透明度的 Opacity 是CSS 3里的一个属性.当然现在还只有少部分浏览器支持. 不过各个浏览器都有自己的私有属性来支持,其中包括老版本的Mozilla和Safari: IE: fil ...
- 获取Spring的上下文环境ApplicationContext的方式
摘自: http://blog.csdn.net/yang123111/article/details/32099329 获取Spring的上下文环境ApplicationContext的方式 Web ...
- 007Linux在线升级yum
1.Linux下如何安装软件:利用rpm命令进行安装: 2.rpm优点:安装过程很简单,不需要做额外的配置逻辑,拿到安装包,通过rpm命令就可以安装: 3.rpm缺点: (1)需要自己四处去找和系统版 ...
- Android IOS WebRTC 音视频开发总结(三六)-- easyRTC介绍
本文主要介绍easyRTC,文章来自博客园RTC.Blacker,支持原创,转载请说明出处. 先看看人家官网的介绍,然后再来解释,这样您可能更容易理解: 以下部分内容属个人看法,如有异议,欢迎探讨: ...
- 计算2的n次方的三种方法(C语言实现)
C代码如下: #include <stdio.h> int func1(int n) { <<n; } int func2(int n) { ) { ; } )*; } int ...