【填空】
1、组队
问题描述
思路 核心:寻找每一号位的最大值
- 枚举,暴力破解
- 缩小范围,寻找每一号位5个最大评分,再进行for循环
代码如下
import os
import sys
s1=[97,92,0,0,89,82,0,0,0,95,0,0,94,0,0,0,98,93,0,0]
s2=[90,85,0,0,83,86,0,97,0,99,0,0,91,83,0,0,83,87,0,99]
s3=[0,96,0,0,97,0,0,96,89,0,96,0,0,87,98,0,99,92,0,96]
s4=[0,0,0,80,0,0,87,0,0,0,97,93,0,0,97,93,98,96,89,95]
s5=[0,0,93,86,0,0,90,0,0,0,0,98,0,0,98,86,81,98,92,81]
ls=[]
'''
#暴力求解:
for i in s1:
for j in s2:
for k in s3:
for x in s4:
for y in s5:
if(i!=j!=k!=x!=y):
ls.append(i+j+k+x+y)
print(max(ls))
'''
s1_5=[]
s2_5=[]
s3_5=[]
s4_5=[]
s5_5=[]
for i in range(0,5):
s1_5.append(max(s1))
s1.remove(max(s1))
for i in range(0,5):
s2_5.append(max(s2))
s2.remove(max(s2))
for i in range(0,5):
s3_5.append(max(s3))
s3.remove(max(s3))
for i in range(0,5):
s4_5.append(max(s4))
s4.remove(max(s4))
for i in range(0,5):
s5_5.append(max(s5))
s5.remove(max(s5))
for i in s1_5:
for j in s2_5:
for k in s3_5:
for x in s4_5:
for y in s5_5:
if(i!=j!=k!=x!=y):
ls.append(i+j+k+x+y)
print(ls)
print(max(ls))
2、数列求值
import os
import sys
print(4659)
3、质数
import os
import sys
import math
print(17569)
4、年号字串
import os
import sys
a = 2019 % 26
b = 2019 // 26
c = b % 26
d = b // 26
list = '*ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(list[d] + list[c] + list[a])
5、数的分解
import os
import sys
ans = 0
for i in range(1,672):
for j in range(i+1,(2019-i)//2+1):
a = str(i)+str(j)+str(2019-i-j)
if 2019 - i - j > j and '2' not in a and '4' not in a:
ans += 1
print(ans)
7、奇数倍数
问题描述
个人思路
- 先判断是2019的整倍数
- 将数,转换为str型,对其for循环遍历,除于2
- 若各位数都为奇数,则输出,并跳出循环
代码
import os
import sys
n = sys.maxsize
for i in range(n):
if i % 2019 ==0:
for j in str(i):
if int(j) % 2 == 0:
break
else:
print(i)
break
8、完全二叉树的权值
问题描述
代码如下
import os
import sys
import math
N = int(input())
A = list(map(int, input().split()))
ans = []
deep = math.ceil(math.log(N+1,2))
b = 0
for i in range(1, deep+1):
c = 2 ** i - 1
ans.append(sum(A[b:c]))
b = c
print(ans.index(max(ans))+1)
【程序设计】
注:临时变量存储总和的时间 < 列表存储数据
【总结】
【填空】 1、枚举爆破,for循环 2、找规律,容易数据溢出,缩小范围 3、枚举暴力 4、取余,获取每个数的每个位数 5、 【程序设计】 1、数学逻辑知识
|