import re
from random import randint
A = []
MaxNum = 999999
MinNum = 0
# 输入堆数x回车,生成x个随机数
inputFile = open('input.txt', 'w')
inputFile.close()
inputFile = open('input.txt', 'a')
print('输入序列数')
x = input()
inputFile.write(x + '\n')
for i in range(int(x)):
s = str(randint(1, 10)) + ' '
inputFile.write(s)
inputFile.close()
# 读取input.txt中的数据并生成列表
inputFile = open('input.txt')
inputContent = inputFile.readlines()
print(inputContent[1])
x = inputContent[0] # 序列个数x
stonesNumRegex = re.compile(r'\d+')
mo = stonesNumRegex.findall(inputContent[1])
A.extend(mo)
B = list(map(int, A))
n = int(x)
def s_sort(B, n):
g1 = 0
i = 0
B.sort()
while i < n - 1:
g1 = g1 + B[i] + B[i + 1] - 1;
B[i] = B[i] + B[i + 1];
B[i + 1] = 0
i += 1
B.sort()
print('最小得分为' + str(g1))
def b_sort(B, n):
g2 = 0
j = 0
B.sort(reverse=True)
for j in range(n - 1):
g2 = g2 + B[0] + B[1] - 1
B[0] = B[0] + B[1]
B[1] = 0
j += 1
B.sort(reverse=True)
print('最大打分为' + str(g2))
s_sort(B, n)
b_sort(B, n)
算法六组
自己的版本