Memories after the 11th Blue Bridge Cup python group match

Feel the difficulty is uneven. It may be that I am not capable enough. . . . .

  1. Post house number

    Find the number of numbers between 1, 2020 that contains 2

    # 找1,2020之间的数中包含2的数的个数
    ans = 0
    for i in range(1, 2021):
        while i != 0:
            a = i % 10
            if a == 2:
                ans += 1
                break
            i = i // 10
    print(ans)  # 563
    
  2. 2020

    Given a data of 0 and 2 with 300 rows and 300 columns, look for the number of 2020 horizontally and vertically.

    I use with open to read the data

    The horizontal one is easy to find, just use line.count('2020')

    Vertical: count() after transposing the matrix

    Oblique: The last question I did at that time, the oblique one should not have been found, so I submitted it. . . .

  3. Run

    Say that Xiaolan ran from the day of the month in 2000 on the day of the week (I can't remember it), including this day, and ran until October 1, 2020 (including this day). Among them, I ran 2000 meters on the 1st every month and 2000 meters on Mondays. It happened that the 1st also ran 2000 meters on Mondays, and the other days I ran 1000 meters. Ask how many kilometers I ran.

    import datetime
    
    dt = datetime.date(2000, 6, 3)  # 2000-06-03周六,就从这天开始吧
    dt2 = datetime.date(2020, 10, 1)
    delta = dt2 - dt  # 中间有多少天
    delta1 = datetime.timedelta(1)
    dist = 0
    ans = 6
    
    for i in range(delta.days):
        dt += delta1
        ans += 1
        if dt.day == 1 or ans % 7 == 1:
            dist += 2
            ans = 1
        else:
            dist += 1
    
    print(dist)  # 8630
    
  4. Sort

    Find the string sequence with the number of counterfeit sort exchanges as 100, the shortest, only lowercase letters, no repetition

    I put it in reverse order, because the smallest is placed at the end and he moves the most times, so as to ensure that the string is the shortest, and finally reaches o, but o is not at the end, and is in the countdown position.

  5. Snakeskin walking

    Such a matrix

    1	2	6	7	15...
    3	5	8	14...
    4	9	13...
    10	12...
    11...
    ...
    

    What is the number in row 20 and column 20

    I used pen to calculate directly, the total is n(n+1)/2 numbers, and then go down

  6. Qualification rate excellent rate

    At least 60 is a pass,
    at least 85 is excellent.
    Calculate the passing rate and the excellent rate.
    Enter the first line n, which represents the product of several people. The bottom n lines are the product of each person. Ensure that the input is an integer >=0. The
    output two lines are respectively The passing rate and the excellent rate, rounded up.
    For example:
    7
    60
    71
    100
    88
    98
    0
    67

    Output

    86%
    43%

    n = int(input())
    jige = good = 0
    for i in range(n):
        s = int(input())
        if 60 <= s < 85:
            jige += 1
        elif s >= 85:
            good += 1
    
    r1 = round((jige+good)/n, 2)
    r2 = round(good/n, 2)
    
    print(int(r1*100), '%', sep='')
    print(int(r2*100), '%', sep='')
    
  7. Plane segmentation

    The straight line is determined by y = Ax + B.
    Input different AB
    and judge that these lines divide the plane into several parts.
    Example
    3
    1 1
    2 2
    3 3
    Output
    6

    class Straight:
        def __init__(self, a, b):
            self.a = a
            self.b = b
    
    def relation(n):
        flag = True
        for i in range(n):
            for j in range(i+1, n):
                if line[i].a != line[j].a:
                    flag = False
                    # 不平行,求交点
                    x = -(line[i].b - line[j].b) / (line[i].a - line[j].a)
                    y = line[i].a * x + line[i].b
                    point.add((x, y))
                    break
        if flag:
            # 所有的线都平行
            return n + 1
        else:
            if len(point) == 1:
                # 所有的线相较于1个点
                return 2 * n
            else:
                # 超过2个交点
                return 2 * n + 1
    
    n = int(input())
    line = []
    point = set()
    
    for i in range(n):
        a, b = list(map(int, input().split()))
        line.append(Straight(a, b))
    
    print(relation(n))
    
  8. Maximum score

    Similar to this

            3
          4   5
        6   7   8
        ...
    

    Then walk from the top to the bottom, only to the bottom left or bottom right, and the difference is at most 1, and finally the value on the route is accumulated to find the largest.

  9. forget

  10. Weapon enhancement

    No, every time the questions are read, it is too long

Guess you like

Origin blog.csdn.net/qq_31910669/article/details/109136837