Atcoder ABC165 A-D in Python

Trouble that the start is delayed by 10 minutes.

A. We Love Golf All the values from a to b are searched, and it is OK if it is divisible by k.

ABC165a.py


a=int(input())
b,c=map(int,input().split())

for i in range(b,c+1):
    if i%a==0:
        print("OK")
        exit()
print("NG")

B. 1% Turn the while statement until the total amount including compound interest exceeds x yen. Don't forget to truncate with floor every time.

ABC165b.py


import math

x=int(input())
y=100
i=0
while True:
    y=math.floor(y*1.01)
    i+=1
    if y>=x:
        print(i)
        exit()

C. Many Requirements I lost a lot of time when I thought about whether to take from the top of the points obtained or whether to delete duplicates of a and b. Since $ N, M, and Q $ are all small, it is enough to search all the expected sequences. Use Itertools combinations_with_replacement to create all possible sequences and output the maximum score.

ABC165c.py


from itertools import *

n,m,q=map(int,input().split())

aaa=[]
for i in range(m):
    aaa.append(i+1)

l=[]
for i in range(q):
    a=list(map(int,input().split()))
    l.append(a)

a=list(combinations_with_replacement(aaa,n))
ans=0

for i in a:
    aa=0
    for j in l:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            aa+=j[3]
    if aa>ans:
        ans=aa
print(ans)

D. Floor function The second term is $ 0 $ when $ x <B $, otherwise it is a positive integer. Therefore, when $ x $ \ equiv $ B-1 (modB) $, $ f (x) $ becomes the maximum, and the function becomes a square wave. As an example, $ f (x) $ when $ a = 100 and b = 20 $ is shown below. ABC165.JPG

Therefore, when $ n> = B $, $ x = b-1 $ should be output, and when $ n <B $, $ x = n $ should be output as $ f (x) $.

ABC165d.py


import math

a,b,n=map(int,input().split())

if b<=n:
    print(math.floor(a*(b-1)/b))
else:
    print(math.floor(a*(n)/b))

I've run out of time until the D problem today ... I want to use what I've learned, such as DP and search algorithms, in practice as soon as possible.

Recommended Posts

Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
Atcoder ABC164 A-C in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Solve ABC169 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python