首页 > 其他分享 >最大连续出牌数量

最大连续出牌数量

时间:2022-08-26 21:44:37浏览次数:58  
标签:tmp 最大 max visted range 连续 res cards 数量

''' 
1 4 3 4 5 6 5 
r y b b r b b
'''

def func(cards):
    n = len(cards)
    matrix = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cards[i][0] == cards[j][0] or cards[i][1] == cards[j][1]:
                matrix[i][j] = 1
    print(matrix)
    visted = [0 for _ in range(n)]
    max_res = 0
    
    tmp = 0
    for idx in range(n):
        if visted[idx] == 0:
            q = [idx]
            visted[idx] = 1
        else:
            continue
        
        while q:
            i = q.pop(0)
            tmp += 1
            for j in range(n):
                if matrix[i][j] == 1 and visted[j] == 0 and i!=j:
                    q.append(j)
                    visted[j]=1
        max_res = max(max_res,tmp)
        tmp = 0
    return max_res 
nums = input().split()
cols = input().split()
cards = []
for i in range(len(nums)):
    s = nums[i]+cols[i]
    cards.append(s)
r = func(cards)
print(r)

标签:tmp,最大,max,visted,range,连续,res,cards,数量
From: https://www.cnblogs.com/ray-mmss/p/16629358.html

相关文章