• 账号发布文章的顺序


    #n个人排序,相邻的两个人的顺序,不能重复出现,求组合数
    import random
    def my_factorial(i):
    r = 1
    for i in range(1, i + 1):
    r *= i
    return r
    uid_l, uid_num, = [], 10
    while len(uid_l)< uid_num:
    i = random.randint(1, 10 ** uid_num)
    if i not in uid_l:
    uid_l.append(i)

    uid_order_list_l, one_order_ele_num, uid_order_list_num = [], 7, 1200
    #必要非充分--算法提升
    uid_order_list_num = uid_order_list_num if uid_order_list_num <= my_factorial(uid_num) else my_factorial(uid_num)
    one_order_ele_num = one_order_ele_num if one_order_ele_num <= uid_num else uid_num

    def gen_pair(num_set=[454, 4545, 54]):
    r, breaker = [], len(num_set) - 1
    for i in range(breaker):
    t = (num_set[i], num_set[i + 1])
    r.append(t)
    return r


    def chk_pair_if_conflict(a=[1, 2, 3], b=[3, 2, 1]):
    parirs_a, parirs_b = gen_pair(a), gen_pair(b)
    for i in parirs_a:
    if i in parirs_b:
    return True
    return False

    #必要非充分--算法提升
    while len(uid_order_list_l) < uid_order_list_num:
    one_order = []
    while len(one_order) < one_order_ele_num:
    i = random.randint(0, uid_num)
    if i not in one_order:
    one_order.append(i)
    if_conflict =False
    for ii in uid_order_list_l:
    if_conflict = chk_pair_if_conflict(one_order, ii)
    if if_conflict:
    break
    if not if_conflict:
    uid_order_list_l.append(one_order)


    132 123 可以;132 213 不可以
    132 123 当然 1 一直在3前边,这一层 后续 再写也可以


  • 相关阅读:
    Java 中文 乱码问题
    JQuery 操作 radio 被坑一例
    标准I/O库之打开和关闭流
    标准I/O库之缓冲
    标准I/O库之标准输入、标准输出和标准出错
    标准I/O库之流和FILE对象
    文件和目录之文件访问权限位小结
    文件和目录之设备特殊文件
    文件和目录之chdir、fchdir和getcwd函数
    文件和目录之读目录
  • 原文地址:https://www.cnblogs.com/rsapaper/p/8352444.html
Copyright © 2020-2023  润新知