[Continuous update] Blue Bridge Cup python group real questions

Principles: 1. All the questions are from the real questions provided by Lanqiao official website over the years

2. Not all are from the python group, but all answers will be written in python language

3. I try to make at least one...

1. Cards

a=[]
for i in range(0,10):
    a.append(2021)       #0到9,每个数字2021张

def num(n):
    while n>0:
        if n/10 == 0:
            a[n]=a[n]-1
        else:
            a[n%10]=a[n%10]-1
            n=n//10

for i in range(1,10000):    #每拼一个数少对应的牌
    num(i)
    if 0 in a:
        print(i)
        break

Two, straight line

When verifying whether my answer is correct, I found a super replacement of my idea, so I posted it:

li = set()   #集合去重
li1 = []

m, n = map(int, input().split())    #输入

for x in range(m):
    for y in range(n):
        li1.append([x, y])    #以坐标点的方式,存储于二维数组中

def sameline(a, b):
    global li
    if a[0] == b[0] or a[1] == b[1]:   #如果在同一条直线上,则不计数
        pass
    else:
        k = (b[1] - a[1]) / (b[0] - a[0])
        b = a[1] - k * a[0]
        li.add((k, b))

for a in li1:
    for b in li1:
        sameline(a, b)

print(m + n + len(li))

 3. Cargo placement

Ah ha ha, here comes the ace pigeon

"Hu Shizhi, Hu Shizhi, how can you be so depraved"

Find the divisor of n first, and then cycle violently

a=[1]
n=2021041820210418
sum=0

for i in range(2,100000000):   
    if n%i==0:
        a.append(i)

for i in a:
    temp=n//i
    if temp not in a:
        a.append(temp)    #列表a存储n的所有约数

for i in range(len(a)):
    for j in range(len(a)):
        for t in range(len(a)):
            if a[i]*a[j]*a[t]==n:
                sum=sum+1

print(sum)   #输出结果2430

Guess you like

Origin blog.csdn.net/shuhuigao/article/details/122442695