其他分享
首页 > 其他分享> > 台球摆放问题

台球摆放问题

作者:互联网

如何摆放,大号小号最分散

>>> links = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 6], [6, 7], [7, 8], [5, 9], [5, 10], [6, 10], [6, 11], [7, 11], [7, 12], [8, 12], [8, 13], [9, 10], [10, 11], [11, 12], [12, 13]]

>>> def score(s=[]): return sum([(c[0] in s) ^ (c[1] in s) for c in links])
...
>>> rs = []
>>> for c in itertools.combinations(range(14), 7): rs.append([c, score(c)])
...
>>> rs[0:10]
[[(0, 1, 2, 3, 4, 5, 6), 7], [(0, 1, 2, 3, 4, 5, 7), 9], [(0, 1, 2, 3, 4, 5, 8), 8], [(0, 1, 2, 3, 4, 5, 9), 6], [(0, 1, 2, 3, 4, 5, 10), 8], [(0, 1, 2, 3, 4, 5, 11), 10], [(0, 1, 2, 3, 4, 5, 12), 10], [(0, 1, 2, 3, 4, 5, 13), 8], [(0, 1, 2, 3, 4, 6, 7), 8], [(0, 1, 2, 3, 4, 6, 8), 9]]
>>> rs_df = pd.DataFrame(rs, columns=['c', 's'])
>>> rs_df.head()
c s
0 (0, 1, 2, 3, 4, 5, 6) 7
1 (0, 1, 2, 3, 4, 5, 7) 9
2 (0, 1, 2, 3, 4, 5, 8) 8
3 (0, 1, 2, 3, 4, 5, 9) 6
4 (0, 1, 2, 3, 4, 5, 10) 8
>>> rs_df.shape
(3432, 2)
>>> 39*16
624
>>> 39*16*11
6864
>>> rs_df['s'].value_counts()
14 602
13 584
12 522
15 508
11 372
16 272
10 218
9 136
17 104
8 66
7 24
6 16
5 8
Name: s, dtype: int64

 

st = rs_df.groupby('s')['c'].size().reset_index()

 

>>> st['r'] = st['c'] / st['c'].sum()
>>> st['rc'] = st['r'].cumsum()
>>> st
s c r rc
0 5 8 0.002331 0.002331
1 6 16 0.004662 0.006993
2 7 24 0.006993 0.013986
3 8 66 0.019231 0.033217
4 9 136 0.039627 0.072844
5 10 218 0.063520 0.136364
6 11 372 0.108392 0.244755
7 12 522 0.152098 0.396853
8 13 584 0.170163 0.567016
9 14 602 0.175408 0.742424
10 15 508 0.148019 0.890443
11 16 272 0.079254 0.969697
12 17 104 0.030303 1.000000

标签:11,10,12,rs,df,摆放,st,问题,台球
来源: https://www.cnblogs.com/Mannigfaltigkeit/p/16151725.html