[GO] [Python] Solve 10 past elite problems of Atcoder

background

I decided to study for the programming test preparation for the entrance exam. Therefore, I will study because AtCoder was a site with many explanations in Japanese.

Purpose

Study for programming test preparation

Introduction

I thought that a site with many explanations would lead to my own study when taking a programming test. Therefore, when I was looking for a place where many programming tests were conducted in the Japanese community, I was studying because there was AtCoder.

Requirement definition

  1. Solve AtCoder Beginners Selection
  2. Solve related problems
  3. Solve 60 LeetCode questions

environment

Result of doing

Question 1: ABC 086 A --Product

a,b=map(int,input().split())
if a*b%2==0:
   print('Even')
else :
    print('Odd')

Question 2: ABC 081 A --Placing Marbles

s=input()
count=0
for i in s:
    # print(i)
    if int(i)==1:
        count+=1
    # print(count)

print(count)

Alternative 1

It's simple and I prefer this one. If I used count on 04/19, it failed with RunTimeError, so it is recommended to use the first answer.

python print(input().count('1'))

###Alternative 2
How to guide your math skills
I don't really recommend it.
If you are good at math, you may like to write it.

print(int(input())%9)



##Question 3: [ABC 081 B - Shift Only](https://atcoder.jp/contests/abc081/tasks/abc081_b)
```python
N = int(input())
A = map(int, input().split())

count = 0

while all(a % 2 == 0 for a in A):
    A = [a / 2 for a in A]
    count += 1

print(count)

##Question 4: ABC 087 B - Coins

A=int(input())
B=int(input())
C=int(input())
X=int(input())

count=0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if X==500*a+100*b+50*c:
                    count+=1

print(count)

##Question 5: ABC 083 B - Some Sums I learned that using a map can be used for convenient sorting. I used it for the first time.

N = int(input())
A = int(input())
B = int(input())
N,A,B=map(int,input().split())

def FindSumOfDigits(num):
    count = 0
    while num > 0:
        count += num % 10
 # This is different / missing
        num=num // 10

    return count

for n in range(1, N+1):
    count = FindSumOfDigits(n)
    if A<= count <=B:
        ans += n
print(ans)

##Question 6: ABC 088 B - Card Game for Two

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

Alice=Bob=0

for i in range(N):
    if i%2==0:
        Alice+=A[i]
    else:
        Bob+=A[i]

print(Alice-Bob)

##Question 7: ABC 085 B - Kagami Mochi

N=int(input())
d=[input() for _ in range(N)]
print(len(set(d)))

##Question 8: ABC 085 C - Otoshidama It was a problem that used mathematical skills such as solving simultaneous equations.

N, Y = map(int, input().split())

res10000 = res5000 = res1000 = -1

for a in range(N + 1):
    for b in range(N + 1 - a):
        c = N - a - b
        if Y == 10000 * a + 5000 * b + 1000 * c:
            res10000 = a
            res5000 = b
            res1000 = c

print(a, b, c)

##Question 9: ABC 049 C - Daydream

s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")

# Rewriting if statement
 print('NO' if s else 'YES')

if s:
  print("NO")
else:
  print("YES")

The idea of searching from behind and erasing

def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

    if len(S) == 0:
        print("YES")
    else:
        print("NO")
main()

##Question 10: ABC 086 C - Traveling Mathematical solution

n=int(input())
for i in range(n):
    t,x,y=map(int,input().split())
    if (x+y) > t or (x+y+t)%2:
        print('No')
        exit()

print('Yes')

###Alternative 1 The royal way to solve


N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(N):
    t[i+1], x[i+1], y[i+1] = map(int, input().split())

f = True
for i in range(N):
    dt = t[i+1] - t[i]
    dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    if dt < dist:
        f = False
    if dist%2 != dt%2:
        f = False

print('Yes' if f else 'No')

###Betsukai 2

import sys

def main():
    N = int(input())
    t, x, y = 0, 0, 0

    for _ in range(N):
        next_t, next_x, next_y = [int(__) for __ in input().split()]

        delta_t = next_t - t
        distance = abs(next_x - x) + abs(next_y - y)

        if distance > delta_t:
            print("No")
            sys.exit()

        if (delta_t - distance) % 2 != 0:
            print("No")
            sys.exit()

        t, x, y = next_t, next_x, next_y

    print("Yes")

main()

#Impressions As for how to solve mathematics, I thought it would be a good idea for people who are not afraid to try to find the law by doing math firmly at school. Mathematically, I feel that I don't use it much because I feel that I have too much thought in competitive programming. #What I can do 1.I learned the basic idea of AtCoder 1.Ability to translate from esoteric problem sentences #Task 1.Try to solve a similar problem from the reference link 1.Challenge Leet Code #References

  1. Solve AtCoder Beginners Selection in Python
  2. I tried to solve 10 past questions of Atcoder with python!
  3. After registering with AtCoder, what to do next-If you solve this much, you can fight enough! Past question selection 10 questions ~
  4. I tried to solve 10 selected past questions that should be solved after registering with AtCoder
  5. I tried to solve AtCoder Beginners Selection in Python

Recommended Posts

[Python] Solve 10 past elite problems of Atcoder
Solve AtCoder Problems Recommendation with python (20200517-0523)
Solve AtCoder 167 with python
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Solve AtCoder ABC166 with python
Solve optimization problems in Python
Solve AtCoder ABC 186 with Python
Solve AtCoder Problems Boot camp for Beginners (Medium 100) with python
Solve Atcoder ABC169 A-D in Python
atCoder 173 Python
AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 113 Review of past questions
AtCoder Beginner Contest 074 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 054 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
[AtCoder] Solve ABC1 ~ 100 A problem with Python
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions