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. ...
随机推荐
- CF997D
分析: 假设在第一个树上我们有一个长度为x的环,在第二树上我们有一个长度为y的环,那么可以在叉积树上构造出$\binom{x+y}{x}$个长度为x+y的环 问题的关键就变成了如何统计出在一个树上的长 ...
- Markdown编辑器的使用
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/LoveJavaYDJ/article/details/73692917 一.Markdown和edi ...
- HTTPS协议工作流程
被问到了,复习一下HTTPS的工作流程 提到https,不得不提SSL SSL 1. 安全套接字(Secure Socket Layer,SSL)协议是Web浏览器与Web服务器之间安全 ...
- Ubuntu 16.04安装Wine版的迅雷+QQ(完美方案,终极解决方法)
安装前先备份好系统! 继上一篇安装QQ的方法http://www.cnblogs.com/EasonJim/p/7425978.html,这一篇的QQ采用的是Wine模式安装.完美解决消息记录中文乱码 ...
- n*n的正方形网格中有多少个长方形
n*n的正方形网格中有横竖各n+1条直线,其中,任意各取两条都可以组成一个长方形﹙正方形也是长方形﹚.所以长方形个数为C﹙n+2,2﹚×C﹙n+2,2﹚=﹙n+1﹚²n²/4个.如果正方形不算,则N= ...
- ubuntu 卸载干净软件(包括配置文件)
var/cache/apt/archives occupying huge space I am in the process of cleaning up my system. And I see ...
- Solaris 下解决上网问题以及远程登录问题
解决乱码问题 参考文章 http://www.jb51.net/os/Solaris/1656.html solaris 显示乱码的解决方法 现象: 利用命令 : LANG=zh; export LA ...
- Spring的Scheme位置
org.springframework.aop.config org.springframework.contex.config org.springframework.ejb.config org. ...
- nodejs REPL(交互式解释器)
Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux ...
- linux查看进程、端口
1 查看进程pidps -ef|grep tomcat 2 查看进程占用的端口netstat -ntlp|grep pid 3 查看端口对应的进程号lsof -i:portid