账号发布文章的顺序

#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前边,这一层 后续 再写也可以


posted @ 2018-01-25 17:48  papering  阅读(315)  评论(0编辑  收藏  举报