[PYTHON] AtCoderBeginnerContest181 Review & Summary

AtCoder ABC181 This is a summary of the AtCoder Beginner Contest 181 problems that took place on 2020-11-01 (Sun), starting with problem A and taking into account the considerations. The problem is quoted, but please check the contest page for details. Click here for the contest page Official commentary PDF

Problem A Heavy Rotation

Problem statement Takahashi is now wearing white clothes. Takahashi wears black clothes the next day when he wears white clothes, and white clothes the next day when he wears black clothes. What color will you wear in $ N $ days?

abc181a.py


n = int(input())
if n % 2 == 0:
    print("White")
else:
    print("Black")

Problem B Trapezoid Sum

Problem statement There is a blackboard with nothing written on it. Takahashi performs $ N $ times and writes an integer on the blackboard. In the _ $ i $ operation, write $ 1 $ each of all integers from $ A_i $ to $ B_i $, for a total of $ B_i−A_i + 1 $ integers. Find the sum of the integers written on the blackboard after completing $ N $ operations.

It was very helpful to have $ B_i−A_i + 1 $ in the problem statement. I often forget to add +1 around here and make mistakes (sweat)

abc181b.py


n = int(input())
total = 0
for i in range(n):
    a, b = map(int, input().split())
    total += (b - a + 1) * (a + b) // 2
print(total)

C problem Trapezoid Sum

Problem statement There are $ N $ points on an infinitely wide $ 2 $ dimensional plane. The $ i $ th point is at $ (x_i, y_i) $. Are there any different $ 3 $ points out of $ N $ points that are on the same straight line?

Being on a straight line means that for three points $ P_1, P_2, P_3 $ k\overrightarrow{P_1P_2}=\overrightarrow{P_1P_3} Since it is necessary to hold, we were able to obtain the conditional expression for holding by eliminating $ k $ from the identity of the x and y components.

abc181c.py


n = int(input())
x_list = []
y_list = []
for i in range(n):
    x, y = map(int, input().split())
    x_list.append(x)
    y_list.append(y)
flag = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            xi = x_list[i]
            xj = x_list[j]
            xk = x_list[k]
            yi = y_list[i]
            yj = y_list[j]
            yk = y_list[k]
            if (xj - xi) * (yk - yi) == (xk - xi) * (yj - yi):
                flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")

D problem Hachi

Problem statement Given a sequence of numbers $ S $ consisting only of the numbers 1-9. Bee Takahashi likes multiples of $ 8 $. Takahashi is trying to rearrange the number sequence $ S $ to make a multiple of $ 8 $. Determine if you can make multiples of $ 8 $.

In order for a certain digit string to be a multiple of $ 8 $, the last three digits must be a multiple of $ 8 $. Therefore, it can be solved by checking whether it is possible to create three digits, which is a multiple of $ 8 $, for a sequence of numbers with three or more digits. First, we recorded a combination of numbers that are multiples of $ 8 $, not including $ 0 $, and confirmed that the numbers required for that combination were sufficient, and made a judgment. I think I can write a simpler code, but I will post the submitted one as it is.

abc181d.py


s = input()
flag = 0
if len(s) == 1:
    if int(s) % 8 == 0:
        flag = 1
elif len(s) < 3:
    if int(s) % 8 == 0:
        flag = 1
    if int(s[1] + s[0]) % 8 == 0:
        flag = 1
else:
    check_list = []
    for i in range(14, 125):
        mozi = str(i * 8)
        if len(mozi) == 3 and "0" not in mozi:
            count_list = [0] * 9
            count_list[int(mozi[0]) - 1] += 1
            count_list[int(mozi[1]) - 1] += 1
            count_list[int(mozi[2]) - 1] += 1
            check_list.append(count_list)
    s_list = [0] * 9
    for suuzi in s:
        s_list[int(suuzi) - 1] += 1
    for count_list in check_list:
        total = 0
        for i in range(9):
            if count_list[i] > 0:
                if count_list[i] <= s_list[i]:
                    total += count_list[i]
        if total == 3:
            flag = 1
            break
if flag == 1:
    print("Yes")
else:
    print("No")

This time, I was able to solve the D problem at a good pace, but I couldn't solve the E problem because it was blocked by'WA'. Since the policy was in place, I would like to make sure that it can be solved next time.

Thank you for reading until the end.

Recommended Posts

AtCoderBeginnerContest180 Review & Summary
AtCoderBeginnerContest181 Review & Summary
AtCoderBeginnerContest182 Review & Summary
AtCoderBeginnerContest183 Review & Summary
AtCoderBeginnerContest179 Review & Summary
AtCoderBeginnerContest178 Review & Summary (second half)
AtCoderBeginnerContest175 Review & Summary (first half)
AtCoderBeginnerContest161 Review & Summary (second half)
AtCoderBeginnerContest164 Review & Summary (second half)
AtCoderBeginnerContest164 Review & Summary (first half)
AtCoderBeginnerContest169 Review & Summary (first half)
AtCoderBeginnerContest176 Review & Summary (second half)
AtCoderBeginnerContest174 Review & Summary (first half)
AtCoderBeginnerContest173 Review & Summary (First Half)
AtCoderBeginnerContest168 Review & Summary (second half)
AtCoderBeginnerContest169 Review & Summary (second half)
AtCoderBeginnerContest165 Review & Summary (first half)
AtCoderBeginnerContest170 Review & Summary (first half)
AtCoderBeginnerContest167 Review & Summary (first half)
AtCoderBeginnerContest166 Review & Summary (second half)
AtCoderBeginnerContest177 Review & Summary (first half)
AtCoderBeginnerContest171 Review & Summary (second half)
AtCoderBeginnerContest168 Review & Summary (first half)
AtCoderBeginnerContest174 Review & Summary (second half)
AtCoderBeginnerContest178 Review & Summary (first half)
AtCoderBeginnerContest171 Review & Summary (first half)
AtCoderBeginnerContest166 Review & Summary (first half)
AtCoderBeginnerContest161 Review & Summary (first half)
AtCoderBeginnerContest173 Review & Summary (second half)
AtCoderBeginnerContest172 Review & Summary (first half)
AtCoderBeginnerContest177 Review & Summary (second half)
AtCoderBeginnerContest176 Review & Summary (first half)
Python Summary
samba summary
Django Summary
python-pptx summary
Linux Summary
Python summary
Django Summary
pyenv summary
String summary 1
pytest summary
matplotlib summary
Function review