循环赛日程表-python实现

因为都是书上的例子,所以只贴代码
k=3
n=2**k
a=np.zeros((n,n))
#
a[0][0]=1
a[1][1]=1
a[1][0]=2
a[0][1]=2

for i in range(1,k):
    half=2**i
    # 左下角的子表中项为左上角子表对应项加2**i
    for row in range(half):
        for col in range(half):
            a[row+half][col]=a[row][col]+half

    # 右上角的子表等于左下角子表
    for row in range(half):
        for col in range(half):
            a[row][col+half]=a[row+half][col]

    # 右下角的子表等于左上角的子表
    for row in range(half):
        for col in range(half):
            a[row+half][col+half]=a[row][col]

print(a)

你可能感兴趣的:(循环赛日程表-python实现)