当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1103:Maze

题目描述
By filling a rectangle with slashes (/) and backslashes (\), you can generate nice little mazes. Here is an example:

As you can see, paths in the maze cannot branch, so the whole maze only contains cyclic paths and paths entering somewhere and leaving somewhere else. We are only interested in the cycles. In our example, there are two of them.

Your task is to write a program that counts the cycles and finds the length of the longest one. The length is defined as the number of small squares the cycle consists of (the ones bordered by gray lines in the picture). In this example, the long cycle has length 16 and the short one length 4.
输入解释
The input contains several maze descriptions. Each description begins with one line containing two integers w and h (1 <= w,h <= 75), the width and the height of the maze. The next h lines represent the maze itself, and contain w characters each; all these characters will be either "/" or "\".

The input is terminated by a test case beginning with w = h = 0. This case should not be processed.
输出解释
For each maze, first output the line "Maze #n:", where n is the number of the maze. Then, output the line "k Cycles; the longest has length l.", where k is the number of cycles in the maze and l the length of the longest of the cycles. If the maze does not contain any cycles, output the line "There are no cycles.".

Output a blank line after each test case.
输入样例
6 4
\//\\/
\///\/
//\\/\
\/\///
3 3
///
\//
\\\
0 0
输出样例
Maze #1:
2 Cycles; the longest has length 16.

Maze #2:
There are no cycles.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-1103

最后修改于 2020-10-29T05:52:45+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000