2018年东北农业大学春季校赛 D wyh的迷宫 【BFS】
题目链接
https://www.nowcoder.com/acm/contest/93/D
思路
BFS模板题
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 5e2 + 5;
const int MOD = 1e9 + 7;
char Map[maxn][maxn];
int flag;
int n, m;
int Move[][2] =
{
-1, 0, // up
1, 0, // down
0,-1, // left
0, 1, // right
};
bool in_range(int x, int y)
{
return (x >= 0 && x < n && y >= 0 && y < m);
}
queue <pii> q;
void bfs()
{
int len = q.size();
for (int i = 0; i < len; i++)
{
int x = q.front().first, y = q.front().second;
q.pop();
Map[x][y] = 'x';
for (int j = 0; j < 4; j++)
{
int next_x = x + Move[j][0];
int next_y = y + Move[j][1];
if (in_range(next_x, next_y) && Map[next_x][next_y] != 'x')
{
if (Map[next_x][next_y] == 't')
{
flag = 1;
return;
}
else
{
Map[next_x][next_y] = 'x';
q.push(pii(next_x, next_y));
}
}
}
}
if (q.size())
bfs();
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d%d ", &n, &m);
int x = -1, y = -1;
for (int i = 0; i < n; i++)
{
scanf("%s", Map[i]);
if (x == -1)
for (int j = 0; j < m; j++)
{
if (Map[i][j] == 's')
x = i, y = j;
}
}
while (!q.empty())
q. pop();
q.push(pii(x, y));
//cout << q.size() << endl;
flag = 0;
bfs();
//for (int i = 0; i < n; i++)
// printf("%s\n", Map[i]);
if (flag)
printf("YES\n");
else
printf("NO\n");
}
}
2018年东北农业大学春季校赛 D wyh的迷宫 【BFS】的更多相关文章
- 2018年东北农业大学春季校赛 D wyh的迷宫【搜索】
链接:https://www.nowcoder.com/acm/contest/93/D来源:牛客网 题目描述 给你一个n*m的迷宫,这个迷宫中有以下几个标识: s代表起点 t代表终点 x代表障碍物 ...
- 2018年东北农业大学春季校赛 K wyh的数列【数论/斐波那契数列大数取模/循环节】
链接:https://www.nowcoder.com/acm/contest/93/K来源:牛客网 题目描述 wyh学长特别喜欢斐波那契数列,F(0)=0,F(1)=1,F(n)=F(n-1)+F( ...
- 2018年东北农业大学春季校赛 I wyh的物品【01分数规划/二分】
链接:https://www.nowcoder.com/acm/contest/93/I来源:牛客网 题目描述 wyh学长现在手里有n个物品,这n个物品的重量和价值都告诉你,然后现在让你从中选取k个, ...
- 2018年东北农业大学春季校赛 F wyh的集合【思维】
链接:https://www.nowcoder.com/acm/contest/93/F来源:牛客网 题目描述 你们wyh学长给你n个点,让你分成2个集合,然后让你将这n个点进行两两连接在一起,连接规 ...
- 2018年东北农业大学春季校赛 B wyh的矩阵【找规律】
链接:https://www.nowcoder.com/acm/contest/93/B来源:牛客网 题目描述 给你一个n*n矩阵,按照顺序填入1到n*n的数,例如n=5,该矩阵如下 1 2 3 4 ...
- 2018年东北农业大学春季校赛 E wyh的集合 【数学】
题目链接 https://www.nowcoder.com/acm/contest/93/F 思路 其实容易知道在两个不同集合里 假设元素个数 分别为 a b 然后对于第一个集合里的每一个元素 都可以 ...
- 2018年东北农业大学春季校赛 E wyh的阶乘 【数学】
题目链接 https://www.nowcoder.com/acm/contest/93/E 思路 其实就是找阶乘的项中5的个数 末尾为什么会出现0 因为存在5的倍数和偶数相乘 有0存在 借鉴 htt ...
- 2018年东北农业大学春季校赛 B wyh的矩阵【规律】
题目链接 https://www.nowcoder.com/acm/contest/93/B 思路 先加入 中间的那行 和中间的那列 再减去 最中间那个数 因为它 加了两次 然后逐行往下加 会发现是一 ...
- 2018年东北农业大学春季校赛-wyh的吃鸡
BFS: 1. 从起点开始BFS,遇到X点则return: 2. vis[px][py][0]代表经过pxpy这点前还没有找到车: vis[px][py][1]代表经过pxpy这点前已经找到车: 3. ...
随机推荐
- CCCC L2-024 部落【并查集】
https://www.patest.cn/contests/gplt/L2-024 首先在一行中输出这个社区的总人数.以及互不相交的部落的个数.随后对每一次查询,如果他们属于同一个部落,则在一行中输 ...
- ML| EM
What's xxx The EM algorithm is used to find the maximum likelihood parameters of a statistical model ...
- mysql 设置默认id自增开始下标
alter table 表名 AUTO_INCREMENT 此处写你想让id从几开始增长的数字:
- IIS下安装memcached管理工具—MemAdmin
1.先看这篇文章 http://www.cnblogs.com/joylee/archive/2013/01/07/memadmin.html . 2.在IIS下安装的php-cgi.exe程序版本为 ...
- ARM 浮点运算
转载: http://www.embedu.org/Column/Column821.htm http://blog.sina.com.cn/s/blog_602f87700100r5xe.html ...
- Android图片缓存之初识Glide(三)
前言: 前面总结学习了图片的使用以及Lru算法,今天来学习一下比较优秀的图片缓存开源框架.技术本身就要不断的更迭,从最初的自己使用SoftReference实现自己的图片缓存,到后来做电商项目自己的实 ...
- Android自定义Dialog效果
上面是效果图. 使用方法: NiftyDialogBuilder dialogBuilder=NiftyDialogBuilder.getInstance(this); dialogBuilder . ...
- Android重写view时onAttachedToWindow () 和 onDetachedFromWindow ()
在重写View的时候,会遇到这两个方法 protected void onAttachedToWindow() Description copied from class: View This is ...
- Scala IDE里的WorkSheet的使用
所见即所得的一个工具, 左边编码,右边立即出结果 https://www.cnblogs.com/zlslch/p/6115118.html
- SQLAlchemy的查询操作Query
查询操作 查询子句使用session的.query()方法来获取Query查询对象.查询对象能够使用一些方法来对应一些查询子句,比如.order_by(),.limit(),.filter()等. 查 ...