编程介的小学生 2017-06-07 02:40 采纳率: 20.5%
浏览 717
已采纳

Left labyrinths

"The instructions to turn always to the left reminded me that such was the common procedure for discovering the central courtyard of certain labyrinths."

in The garden of forking paths by Jorge Luis Borges

A fellow librarian has exhumed in the Library of Babel a vast catalogue of labyrinths. It is our duty to classify them all and we count on your assistance. The plans of the labyrinths are already digitized and we need you to write a program to decide if the central courtyard of a given labyrinth can be reached following the simple procedure of always turning left at any intersection, and thus be called a left labyrinth.

The digitalization process reduces the plan of a labyrinth to a grid of cells, being each cell either a block of wall or just flooor. Walls are sequences of contiguous blocks, forming either horizontal or vertical corridors between them. Each labyrinth has a single entrance, a hole in its exterior walls, and a single central courtyard. The courtyard differs from the corridors in the shape: a floor cell in a corridor has at least 2 block of wall on each side. You can assume that each plan has a single labyrinth and its outside walls can be contoured within the plan.

Input

The first two input lines are the integers, smaller than 100,

n - the number of lines in the map, and
m - the number of characters per line in the map.

The following n lines, each with m characters, have only two valid character values:

- (sharp) representing a block of wall;

. - (point) representing part of the floor.

Process to the end of file.

Output

Your program must write either YES if the given labyrinth is a left labyrinth or NO otherwise.

Sample Input

30
50
..................................................
..................................................
..................................................
.....##############..............############.....
.....#.........#..#..............#..........#.....
.....#.#######.#.##..............#.########.#.....
.....#.#.....#....#..............#.#......#.#.....
.....#.#.#####.####..............#.#.####.#.#.....
.....#.#.....#...#################.#.##.#...#.....
.....#.#####.###........................#.#.#.....
.....#.........#.###############.#.##########.....
.....#########.#.#.#...........#.#..#.............
.............#.#.#.#...........###.##.............
.............#.#.#.#...........#....#.............
.............#.#...#...........#.##.#.............
.............#######...........#.##.#.............
.............#.................#.#..#.............
.............#.#################.####.............
.....#########...#.................##########.....
.....#.........###.#.#.##########.#######.#.#.....
.....#.#########.....#.#..........#.....#.#.#.....
.....#.#.........#####.##########.#.###.#.#.#.....
.....#.######.#####...........#.#.#.#.#.#.#.#.....
.....#......#.....#...........#.....#.#.#.#.#.....
.....#.##########.#...........#####.#.#.#.#.#.....
.....#............#...........#...........#.#.....
.....##############...........###############.....
..................................................
..................................................
..................................................

Sample Output

YES

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀