TVP

# 单机游戏选择之后还能退回重选！与这个算法有关

defquick_sort(origin_items, comp=lambda x, y: x

items=origin_items[:]

_quick_sort(items, 0, len(items) - 1, comp)

returnitems

def_quick_sort(items, start, end, comp):

ifstartend:

pos = _partition(items, start, end, comp)

_quick_sort(items, start, pos - 1, comp)

_quick_sort(items, pos + 1, end, comp)

def_partition(items, start, end, comp):

pivot=items[end]

i = start - 1

forjinrange(start, end):

ifcomp(items[j], pivot):

i += 1

items[i], items[j] = items[j], items[i]

items[i + 1], items[end] = items[end], items[i + 1]

returni + 1

defqueen(A, cur=0):

ifcur == len(A):

print(A)

return

forcolinrange(len(A)):

A[cur], flag = col, True

for row in range(cur):

ifA[row] == col or abs(col - A[row]) == cur - row:

flag=False

break

ifflag:

queen(A, cur+1)

queen([None]*8)

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20191204A0RB9O00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2018-02-06

2019-11-29

2020-12-07

2020-03-14

2019-01-07

2019-01-25

2018-01-30

2020-05-25

2020-05-23

2023-11-22

2018-02-19

2018-02-19

2018-03-23

2023-11-09

2018-05-04

2020-06-17

2018-01-28

2020-03-03

2018-06-20

2021-06-17