题目连接

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. [ Office 365 开发系列 ] 开发模式分析

    前言 本文完全原创,转载请说明出处,希望对大家有用. 在正式开发Office 365应用前,我们先了解一下Office 365的开发模式,根据不同的应用场景,我们选择最适合的开发模式. 阅读目录 Of ...

  2. 慕课网-安卓工程师初养成-2-1 Java中的关键字

    来源:http://www.imooc.com/code/1176 Java 中常用关键字: 问:这么多,记不住啊......-_-|| 答:现在不需要你记住所有,混个眼熟即可,在学习的过程中,你会逐 ...

  3. My Rules of Information

    http://www.infotoday.com/searcher/jan02/block.htm I often suggested to students that information is ...

  4. 洛谷P2729 饲料调配 Feed Ratios

    P2729 饲料调配 Feed Ratios 36通过 103提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 农夫约翰从来只用调 ...

  5. leetcode 21

    合并两个有序数列.属于基础的数据结构问题,核心在于对链表的操作. 代码如下: /** * Definition for singly-linked list. * struct ListNode { ...

  6. hdu2072

    注意输入全是0的情况. #include <stdio.h> #include <string.h> #include <algorithm> using name ...

  7. 将ubuntu12.04中,gcc4.6/g++4.6版本降低到gcc4.4/g++4.4.

    降低Ubuntu中gcc和g++的版本 ubuntu 12.04 中带的gcc/g++都是4.6,将其降到4.4. 操作步骤如下: 一.降低gcc版本 1. $sudo apt-get install ...

  8. Linux使用有线上网教程

    本人亲测Linux(Ubuntu kylin 14.04)有线上网方法,下面是步骤: 一,运行Terminal(终端),输入  sudo pppoeconf  命令,设置账号和密码后,其他的全选yes ...

  9. 插入排序与shell排序(希尔排序)

    1 .插入排序的过程如同我们平时打扑克牌取牌插入的过程,不断将取出的扑克牌插入已经排好的地方. 插入排序过程初始有序区间大小为1,取出无序区间的首元素,查找有序区间的合适位置,进行插入.不断重复上述过 ...

  10. JSP ajax跨域问题 怎么处理 原因:CORS 头缺少 'Access-Control-Allow-Origin')。 ajax http 415

    /** * Project Name:cm2mManage * File Name:CrossSiteFilter.java * Package Name:com.yoxnet.serverframe ...