题目连接

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)的更多相关文章

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

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

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

    Dating with girls(2) Time Limit: 2000/1000 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. HTTP 500.22 错误解决

    打开网站对应的应用池-->高级设置-->托管管道模式改为classic

  2. 洛谷P1215 [USACO1.4]母亲的牛奶 Mother's Milk

    P1215 [USACO1.4]母亲的牛奶 Mother's Milk 217通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 ...

  3. No.013 Roman to Integer

    13. Roman to Integer Total Accepted: 95998 Total Submissions: 234087 Difficulty: Easy Given a roman ...

  4. 注册码 myeclipse6.5-6.8

    package controllersli; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...

  5. dell n2000 组播抑制

    http://en.community.dell.com/support-forums/network-switches/f/866/t/19677497 http://en.community.de ...

  6. 在ASP.NET开始执行HTTP请求的处理程序之前

    using Dscf.Client.Web.Class; using Dscf.Client.Web.DscfService; using Dscf.Client.Web.Handler; using ...

  7. magento2 客户端模式less样式修改。

    后台模式改为客户端编译,修改less后要删除静态文件,然后清除缓存,清除浏览器缓存.刷新多次后生效.

  8. React模板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. oracle11g ORA-12505

    对于这个问题我前一天还可以用的,第二天打开就报这个错误了. 我在网上找了很多方法,大多为修改/listener.ora这个文件里的SID,修改后也没弄好. 我的解决方法很简单, 打开Oracle Ne ...

  10. javaSE第十三天

    第十三天    76 1. StringBuffer(掌握)    76 (1)说明:    77 (2)StringBuffer的构造方法    77 (3)StringBuffer的常见功能    ...