企业如何利用HarmonyOS开发工具提升小程序开发效率与合规性
584
2022-09-05
HZAU 1208 Color Circle (dfs)
Description
There are colorful flowers in the parterre in front of the door of college and form many beautiful patterns. Now, you want to find a circle consist of flowers with same color. What should be done ?Assuming the flowers arranged as matrix in parterre, indicated by a N*M matrix. Every point in the matrix indicates the color of a flower. We use the same uppercase letter to represent the same kind of color. We think a sequence of points d1, d2, … dk makes up a circle while:Every point is different.k >= 4All points belong to the same color.For 1 <= i <= k-1, di is adjacent to di+1 and dk is adjacent to d1. ( Point x is adjacent to Point y while they have the common edge).N, M <= 50. Judge if there is a circle in the given matrix.
Input
There are multiply test cases.In each case, the first line are two integers n and m, the 2nd ~ n+1th lines is the given n*m matrix. Input m characters in per line.
Output
Output your answer as “Yes” or ”No” in one line for each case.
Sample Input
3 3AAAABAAAA
Sample Output
Yes
题意
对于一张地图,判断能否找到一条路线,长度大于4,相同字母,并且回到原点。
思路
找图中的一个环,可以从某个点进入开始 dfs ,标记已经访问过的点,如果遍历过程中遇到它们,则找到一个环,输出 Yes ,否则输出 No 。
时间复杂度: O(n×m)
AC 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~