[PYTHON] ABC174

We participated in AtCorder Beginner Contest 174. It was ABD's 3 questions AC. I'm using Python3.

A problem

Conditional branch with if.

import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    s=int(input())
    if s >= 30:
        print("Yes")
    else:
        print("No") 

    
if __name__ == "__main__":
    main()

B problem

Put the squared value of the i-th point and the distance from the center in the list L [i]. Whether this is greater than the square of D is determined by if.

import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N, D = map(int,input().split())
    X = [0] * N
    Y = [0] * N
    L = [0] * N
    ans = 0
    for i in range(N):
        X[i], Y[i] = map(int, input().split())
        L[i] = X[i] ** 2 + Y[i] ** 2
        if L[i] <= D ** 2:
            ans += 1
    print(ans)


    
if __name__ == "__main__":
    main()

C problem

Find the number that is $ 0 $ by dividing the sequence of $ 7, 77, 777, ... $ by $ K $. Since the sequence increases to $ 70, 700, 7000 ... $, it is only valid if $ K $ and $ 10 $ are relatively prime. (Because this sequence is a multiple of $ 7 $, it is $ 10 $ instead of $ 70 $)
First, when K is a multiple of $ 2 $ or a multiple of $ 5 $, the multiple of K does not appear in the sequence, so we will classify the cases. Next, create a sequence of $ 7, 77, 777, ... $, and repeat it with a while statement until the remainder after dividing by K becomes $ 0 $. $ x = (x + 7 * 10 ** i)% K $ instead of $ x = (x * 10 + 7)% K $ Then it takes time to calculate $ 7 $ * $ 10 $ ** $ i $, so it becomes TLE. (Edited on 2020/08/04) Below are the answers that became AC after the time was over.

import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    i = 0
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
        exit()
    
    while True:
        x = (x * 10 + 7) % K
        i += 1
        if x == 0:
            print(i)
            break


if __name__ == "__main__":
    main()

D problem

Arrange the N stones arranged from left to right so that they are R on the left side and W on the right side. If you read the problem statement, you will find the operation of swapping two stones and the operation of changing the color of one stone. However, considering arranging with the minimum number of operations, it can be seen that only the operation of exchanging the two stones is required.
First, read the order of the stones as a character string and find the number w of white stones. The 0th to wth stones from the left should be white stones, so find the number of red stones in this range. This is the number to do and the answer.

import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    c = list(input())
    w = c.count("R")
    hidari = c[:w]
    ans = 0
    for i in hidari:
        if i == "W":
            ans += 1
    print(ans)

    
if __name__ == "__main__":
    main()

Recommended Posts

ABC168
ABC164
ABC174
ABC175
ABC170
ABC182
ABC153
ABC146 Impressions
AtCoder ABC176
ABC167 WriteUp
AtCoder ABC177
Beginner ABC156 (Python)
abc154 participation report
abc155 participation report
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
Beginner ABC155 (Python)
Beginner ABC157 (Python)
AtCoder ABC 175 Python
Atcoder ABC115 Past Exercises
Solve ABC169 in Python
ABC147 C --HonestOrUnkind2 [Python]