多多的排列函数 拼多多[编程题]

在这里插入图片描述

在这里插入图片描述

找规律
求最小值 只需要从大到小排列(从1开始 最小值的规律是1 1 0 0 1 1 0 0 … )
求最大值 只需要将最大的N放在最后一个 前面N-1个 是 MID,MID+1,…,N-1,MID-1,… 1即可
从1开始 最大值规律是 i i-1 i-1 i i i-1 i-1 …
找规律即可得 得到如下代码

n = int(input())
for _ in range(n):
    N = int(input())
    if N%2==0:
        minres = 0 if (N//2)%2 == 0 else 1
        maxres = N if (N//2)%2 == 0 else N-1
    elif N%2 == 1:
        minres = 0 if ((N+1)//2) % 2 == 0 else 1
        maxres = N if N == 1 or (N-1)//2%2 == 0 else N-1
    print(minres,maxres)

猜你喜欢

转载自blog.csdn.net/weixin_41545780/article/details/107726904
今日推荐