题解 | #杨辉三角的变形#

杨辉三角的变形

https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43

# 我的评价是赖皮 证明的要求远大于程序实现
# 从第三行开始 首位偶数的位置表现为1,3,2,4,……并循环
n = int(input())
if n <=2:
    print(-1)
else:
    tmp = (n-2)%4
    if tmp == 1 or tmp == 3:
        print(2)
    elif tmp == 2:
        print(3)
    else:
        print(4)

# # 第2层开始 12321起 每层0-3位元素必有至少一个偶数
# # 只计算前4列
# n = int(input())
# # 表示层数
# if n < 4:
#     if n <= 2:
#         print(-1)
#     if n == 3:
#         print(1)
# else:
#     # n = 4 开始 考虑a3
#     a1 = n - 1
#     a2 = (n-1) * (n) / 2
#     a3 = 7
#     if n > 4:
#         # 第5层开始考虑a3累加
#         for i in range(4 + 1, n+1):
#             a3 += (i-2) + (i-2)*(i-1)/2
#             # 上一层的a1 a2
#     # print(a1)
#     # print(a2)
#     # print(a3)
#     if a1 % 2 == 0:
#         print(2)
#     elif a2 % 2 == 0:
#         print(3)
#     elif a3 % 2 == 0:
#         print(4)



# n = int(input())
# # 表示层数
# tower = [[1]]
# for i in range(n-1):
#     tower.append([])
# # 创建n层塔
# for i in range(1, n):
#     # 开始填充
    
#     for j in range(i+1):
#         # 只用输出一半
#         tmp_l = 0
#         # 左位
#         tmp_m = 0
#         # 中位
#         tmp_r = 0
#         # 右位
        
#         # 填充第i层第j位 从0开始

#         # print(f'i:{i} j:{j}')
#         tmp = 0
#         try:
#             # print(1)
#             tmp_l = tower[i-1][j-2]
#             if j < 2:
#                 tmp_l = 0
#         except:
#             # print(2)
#             tmp_l = 0

#         try:
#             tmp_m = tower[i-1][j-1]
#             if j < 1:
#                 tmp_m = 0
#         except:
#             tmp_m = 0

#         try:
#             tmp_r = tower[i-1][j]
#             if j == i:
#                 tmp_r = tmp_l
#         except:
#             tmp_r = 0
#             if j == i:
#                 tmp_r = tmp_l
            
#         tmp = tmp_l + tmp_m + tmp_r
#         # print(f'tmp_l :{tmp_l }')
#         # print(f'tmp_m :{tmp_m }')
#         # print(f'tmp_r :{tmp_r }')
#         # print(f'tmp : {tmp}')
#         tower[i].append(tmp)

# for i in range(len(tower[n-1])):
#     tmp_0 = -1
#     for j in range(len(tower[i])):
#         if  tower[i][j] % 2 == 0:
#             tmp_0 = j+1
#             break
#     print(tmp_0, end=' ')
#     print(tower[i])


# tmp_0 = -1
# for i in range(len(tower[n-1])):
#     if tower[n-1][i] % 2 == 0:
#         tmp_0 = i+1
#         break
# print(tmp_0)

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务