ABC170

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

A problem

Put the input in the list and find the number 0 (index).

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


def main():
    A = list(map(int,input().split()))
    print(A.index(0) + 1)

    
if __name__ == "__main__":
    main()

B problem

It is a sword calculation. Assuming all animals are cranes, divide the number of remaining legs by the difference between the number of crane and turtle legs (4-2 = 2). However, since the sword calculation does not hold in all cases, consider an exception. 1 Too many / too few legs 2 Number of legs that cannot be combined (odd number, etc.)

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


def main():
    X, Y = map(int,input().split())
    a = Y - 2 * X
    if a >= 0 and a % 2 == 0 and a / 2 <= X:
        print('Yes')
    else:
        print('No')

    
if __name__ == "__main__":
    main()

C problem

Find the difference between the input value p and the integer X and create a new list p_new. The answer is 0 → ± 1 → ± 2 when you search the list repeatedly with a while statement and cannot find it. However, if there are multiple, the smaller one is answered, so the value obtained by subtracting the absolute value num is answered.

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


def main():
    X, N = map(int,input().split())
    p = list(map(int,input().split()))
    p_new = [i - X for i in p]
    num = 0
    while num in p_new and -num in p_new:
        num += 1
    if X - num in p:
        print(X + num)
    else:
        print(X - num)

    
if __name__ == "__main__":
    main()

Recommended Posts

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