简单BFS。

 /* 2579 */
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; #define MAXN 105 typedef struct node_t {
int x, y, t;
node_t() {}
node_t(int xx, int yy, int tt) {
x = xx; y = yy; t = tt;
}
} node_t; int n, m, b;
bool visit[MAXN][MAXN][];
char map[MAXN][MAXN];
node_t beg;
int dir[][] = {
-,,,,,-,,
}; inline bool check(int x, int y) {
return x< || x>=n || y< || y>=m;
} int bfs() {
int i, j, k;
int x, y, t;
node_t nd;
queue<node_t> Q; memset(visit, false, sizeof(visit));
visit[beg.x][beg.y][] = true;
Q.push(beg); while (!Q.empty()) {
nd = Q.front();
Q.pop();
t = nd.t + ;
k = t%b;
for (i=; i<; ++i) {
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (check(x,y) || visit[x][y][k])
continue;
if (k && map[x][y]=='#')
continue;
if (map[x][y] == 'G')
return t;
visit[x][y][k] = true;
Q.push(node_t(x, y, t));
}
} return -;
} int main() {
int t;
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif beg.t = ;
scanf("%d", &t);
while (t--) {
scanf("%d %d %d", &n,&m,&b);
for (i=; i<n; ++i) {
scanf("%s", map[i]);
for (j=; j<m; ++j) {
if (map[i][j] == 'Y') {
beg.x = i;
beg.y = j;
}
}
}
k = bfs();
if (k < )
puts("Please give me another chance!");
else
printf("%d\n", k);
} return ;
}

【HDOJ】2579 Dating with girls(2)的更多相关文章

  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. hdoj 2579 Dating with girls(2)【三重数组标记去重】

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

  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】1068 Girls and Boys

    匈牙利算法,最开始暴力解不知道为什么就是wa,后来明白,一定要求最优解.查了一下匈牙利算法相关内容,大致了解. #include <stdio.h> #include <string ...

  5. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  6. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  7. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  8. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  9. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

随机推荐

  1. Qt 学习之路 2(80):定位器

    QML 提供了很多用于定位的元素.这些元素叫做定位器,都包含在 QtQuick 模块.这些定位器主要有 Row.Column.Grid和Flow等. 为了介绍定位器,我们先添加三个简单的组件用于演示: ...

  2. Thread Runnable 多线程

    1. 实现多线程的两种方法         a) 让这个类继承java.lang.Thread,然后重写run方法         b) 让这个类实现 java.lang.Runnable接口,实现r ...

  3. Java基础知识强化之集合框架笔记37:用户登录注册案例

    1. 登录注册案例分析图解: 2. 用户登录案例 详细分析 和 分包实现: (1)用户登录案例详细分析(面向对象思想) 按照如下的操作,可以让我们更符合面向对象思想: • 有哪些类呢?         ...

  4. SQL Server DBA工作内容详解

    在Microsoft SQL Server 2008系统中,数据库管理员(Database Administration,简称为DBA)是最重要的角色.DBA的工作目标就是确保Microsoft SQ ...

  5. [转帖]FPGA--Vivado

    来源:http://home.eeworld.com.cn/my/space-uid-639749-blogid-267593.html 一般的,在Verilog中最常用的编码方式有二进制编码(Bin ...

  6. iOS sizeWithFont 过期 is deprecated

    原文: http://www.cnblogs.com/A--G/p/4819189.html iOS 2.0之后 sizeWithFont就被弃用了: //计算textview 高度 - (float ...

  7. Python:标准数据类型6种

    #!/usr/bin/python3 #python的基本语法和数据类型 #python3中 一行有多个语句,用分号分割(;) print("aaa") ;print(" ...

  8. Android界面布局学习总结

    参考文章: http://blog.csdn.net/shakespeare001/article/details/7843460 http://www.cnblogs.com/w-y-f/p/412 ...

  9. [LeetCode OJ] Best Time to Buy and Sell Stock I

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  10. stat 的名字接口

    File::stat - stat 的名字接口 名字为:dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksiz ...