[CodeForces - 197D] D - Infinite Maze
D - Infinite Maze
We've got a rectangular n × m-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (x, y) is a wall if and only if cell is a wall.
In this problem is a remainder of dividing number a by number b.
The little boy stood at some cell on the plane and he wondered whether he can walk infinitely far away from his starting position. From cell (x, y) he can go to one of the following cells: (x, y - 1), (x, y + 1), (x - 1, y) and (x + 1, y), provided that the cell he goes to is not a wall.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1500) — the height and the width of the maze that the boy used to cyclically tile the plane.
Each of the next n lines contains m characters — the description of the labyrinth. Each character is either a "#", that marks a wall, a ".", that marks a passable cell, or an "S", that marks the little boy's starting point.
The starting point is a passable cell. It is guaranteed that character "S" occurs exactly once in the input.
Output
Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes).
Example
5 4##.###S##..##.###..#
Yes
5 4##.###S##..#..#.#.##
No
Note
In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.
In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the maze traps the boy.
题目的大意就是,给一张网格图,某些地方可以走,其余的则不行,然后某个人从某个点出发,一直在迷宫走,如果走出边界,则回到这个迷宫内相应的地方(当然要可以走),问你是否能走到一个"新的"起点位置.
一开始,我以为这题很水,DFS一遍就好,在四个边界上,上下,左右的同一个位置,找一下是否都能从起点访问到,就输出yes.后面发现这个想法太naive了,好的反例能hack掉,又加了一道,但是又被hack...
然后失去了信心.到比赛结束后才发现反例,然后很难改,于是换了一种思路,直接根据题意进行模拟就好了,知道满足要求,然后竟然就过了...qwq
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mp make_pair
using namespace std;
,fl[][]={{,},{,},{-,},{,-}};
int n,m,Sx,Sy;
pair<int,int> vis[maxn][maxn];
char c[maxn][maxn];
bool v[maxn][maxn];
&&x<n&&y>-&&y<m&&c[x][y]!='#'&&!v[x][y];}
bool DFS(int x,int y){
int xx=x,yy=y;
) xx+=n; xx%=n;
) yy+=m; yy%=m;
);}
;
v[xx][yy]=,vis[xx][yy]=mp(x,y);
; i<; i++) DFS(x+fl[i][],y+fl[i][]);
}
int main(){
scanf(];
; i<n; i++){
scanf(; j<m; j++){
c[i][j]=s[j];
if (c[i][j]=='S') Sx=i,Sy=j;
}
}
if (DFS(Sx,Sy)) puts("Yes"); else puts("No");
;
}
[CodeForces - 197D] D - Infinite Maze的更多相关文章
- 【codeforces 196B】Infinite Maze
[题目链接]:http://codeforces.com/problemset/problem/196/B [题意] 给你一个n*m的棋盘; 然后你能够无限复制这个棋盘; 在这个棋盘上你有一个起点s; ...
- Codeforces 197D - Infinite Maze
197D - Infinite Maze 思路:bfs,如果一个点被搜到第二次,那么就是符合要求的. 用vis[i][j].x,vis[i][j].y表示i,j(i,j是取模过后的值)这个点第一次被搜 ...
- Infinite Maze CodeForces - 196B
We've got a rectangular n × m-cell maze. Each cell is either passable, or is a wall (impassable). A ...
- CodeForces 196B Infinite Maze
Infinite Maze time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- xtu summer individual 3 C.Infinite Maze
B. Infinite Maze time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Infinite Maze
从起点开始走,对于可以走到的位置,都必定能从这个位置回到起点.这样,对地图进行搜索,当地图中的某一个被访问了两次,就能说明这个地图可以从起点走到无穷远. 搜索的坐标(x,y),x的绝对值可能大于n,的 ...
- CodeForces 622 A.Infinite Sequence
A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 675A A. Infinite Sequence(水题)
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 622A A. Infinite Sequence (二分)
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- 51nod 1215 数组的宽度(单调栈)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1215 题意: 思路: 计算出以第i个数为最大值的区间范围,l_max[i ...
- windows下远程连接Mysql
使用“Ctrl + R”组合键快速打开cmd窗口,并输入“cmd”命令,打开cmd窗口. 使用“mysql -uroot -proot”命令可以连接到本地的mysql服务. 使用“use mysql” ...
- 动态 hover 使用变相使用
使用 onmouseover 和 onmouseout 代替 hover foreach (var menu in Model.OrderBy(x => x.Order).Where(x ...
- spring boot配置druid数据源和监控配置
直接上代码: 一.pom.xml中添加依赖 <dependency> <groupId>com.github.drtrang</groupId> <artif ...
- Xcode打包上传遇到的坑
1.安装测试包的时候提示APIInternalError ①是否增加了测试设备的UUID ②是否使用adhoc证书打包 2.打包错误:error: couldn't remove '/Users/xx ...
- tomcat允许跨域请求:
在springmvc-servlet.xml中配置 <mvc:interceptors> <bean class="com.read.api.pc.interceptor. ...
- 日常英语---十一、MapleStory/Monsters/Level 201-210(Dark Demon Eagle Rider)
日常英语---十一.MapleStory/Monsters/Level 201-210(Dark Demon Eagle Rider) 一.总结 一句话总结:骑着鹰的快速飞行的恶魔,进入地图后跟着你. ...
- legend2---开发日志2(注释和函数比较好的写法)
legend2---开发日志2(注释和函数比较好的写法) 一.总结 一句话总结: 函数用_接意群 注释的关键字用[]括起来 注释的步骤用中文的步骤二字 1.为何以步骤为名写注释? 结构非常清晰 //步 ...
- centos 安装npm node
最近那vue全套造了个管理系统的轮子,发现node简直太好用了. elment-UI的出现就是不懂ui设计的后台工程师的福音~ 正好自己买的两个云服务器空闲着没用,就拿来试试看了 首先软件都安装在/u ...
- 雷林鹏分享:C# 环境
C# 环境 在这一章中,我们将讨论创建 C# 编程所需的工具.我们已经提到 C# 是 .Net 框架的一部分,且用于编写 .Net 应用程序.因此,在讨论运行 C# 程序的可用工具之前,让我们先了解一 ...