[Continuous update] Blue Bridge Cup python group Zhenti

Principles: 1. All the questions are from the past real questions provided by the official website of Blue Bridge

2. Not necessarily all of the python group, but all answers will be written in python language

3. I try to do at least one a day...

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

2. Straight line

While verifying my answer was correct, I found a superior replacement for 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. The placement of goods

Ahaha, here comes the ace pigeon

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

First find the divisor of n, 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 http://43.154.161.224:23101/article/api/json?id=324063968&siteId=291194637