用户输出
Yes
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20637 | #1037. 膨胀的tyx | Accepted | 100 | 3498 ms | 35748 K | C++ 11 / 1.8 K | JM233333 | 2019-07-27 23:47:24 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
class Point {
public:
int x, y;
Point(int i, int j) : x(i), y(j) {}
Point() {}
friend bool operator==(const Point& A, const Point& B) { return (A.x == B.x && A.y == B.y); }
friend bool operator!=(const Point& A, const Point& B) { return !(A == B); }
};
bool bfs(Point st);
bool is_legal(int x, int y);
const int dx[] = { 1, -1, 0, 0 };
const int dy[] = { 0, 0, 1, -1 };
const Point NPT = Point(-1, -1);
const int MAX = 2005;
char maze[MAX][MAX];
Point from[MAX][MAX];
int n, m;
int main() {
// freopen("test.txt", "r", stdin);
while (scanf("%d %d", &n, &m) != EOF) {
// 初始化
memset(from, -1, sizeof(from));
// 输入
for (int i = 0; i < n; i++) {
scanf("%s", maze[i]);
}
// 获取起点
Point st;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (maze[i][j] == 'S') {
st = Point(i, j);
}
}
// BFS
bool flag = bfs(st);
// 输出
if (flag) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
// 广度优先搜索
bool bfs(Point st) {
// 主循环
queue<Point> q;
q.push(st);
while (!q.empty()) {
// 出队
Point p = q.front();
q.pop();
// 遍历邻接节点
for (int i = 0; i < 4; i++) {
// 获取邻接节点
int ax = p.x + dx[i], ay = p.y + dy[i];
int rx = ax, ry = ay;
rx = ((rx % n) + n) % n;
ry = ((ry % m) + m) % m;
// 不可通行
if (maze[rx][ry] == '#') {
continue;
}
// 入队
if (from[rx][ry] == NPT) {
from[rx][ry] = Point(ax, ay);
q.push(Point(ax, ay));
} else if (from[rx][ry] != Point(ax, ay)) {
return true;
}
}
}
// 返回
return false;
}
用户输出
No
系统信息
Exited with return code 0
用户输出
Yes
系统信息
Exited with return code 0
用户输出
No
系统信息
Exited with return code 0
6 20
#.##.##.##.##.##.##.
#.##.##.##.##.##.##.
#.##.##.##.##.##.##.
S.#..#..#..#..#..#..
##..#.
<36 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
用户输出
No
系统信息
Exited with return code 0
2000 2000
S#########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
S.........................................................................................
<4001910 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
S.........................................................................................
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
S.........................................................................................
<4001910 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#S########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
##########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
##########################################################################################
<4001910 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
##########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#.###.##.#.#.###..#.#.#...##....##...#..#.#......##.###.##.#..##...##...########.###..#.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#.###.##.#.#.###..#.#.#...##....##...#..#.#......##.###.##.#..##...##...########.###..#.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#.###.##.#.#.###..#.#.#...##....##...#..#.#......##.###.##.#..##...##...########.###..#.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.######..##.###..##...#...#.#.#...#.######.#.#######.#...##.#########..#.##.#...##.###.#
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.######..##.###..##...#...#.#.#...#.######.#.#######.#...##.#########..#.##.#...##.###.#
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.######..##.###..##...#...#.#.#...#.######.#.#######.#...##.#########..#.##.#...##.###.#
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#...##...##....#.#....#.#.####..#.....###......##...#....##..##..#######...###.#.#.#...#
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
..##.....##..#.#..#..#.#..###....##.....#...#...........#.####......#..##.....###..#.#..#
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
###....#..........#.#.......####..#.#.#.#.##...####..##..##............#..#.##..#.#...##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0