[PYTHON] I participated in AtCoder (ABC158)

Hello! This is the roadrice field of a master's student in bioinformatics! Actually, I participated in AtCoder as a hobby, but if I have time from this time, I will keep a record for my review! This time is a record when I participated in ABC158 held on March 7, 2020. I could only AC up to D problem due to lack of study, but I will do my best to AC up to E in the future! I usually use C ++ as well, but this time it seemed that Python would be enough, so I solved it all in Python!

Problem A

At first, I couldn't grasp the intention of the question sentence, and I ended up asking "What?", But if you think about it, you just have to judge whether the given character string * S * is made up of only the same characters. is.

My answer

S = input()
if S[0] == S[1] and S[1] == S[2] and S[0] == S[2]: print("No")
else: print("Yes")

B problem

After all, Takahashi only periodically puts * A * blue balls and * B * red balls, so there are * (A + B) * sets from the front to * N *. First, find the quotient × * A *. If it is greater than * A *, add * A * to it, and if it is less than * A *, add too much itself. Is the answer.

My answer

N, A, B = map(int, input().split())
 
div = int(N/(A+B))
 
amari = N%(A+B)
 
if amari > A:
    print(A*div + A)
else:
    print(A*div + amari)

C problem

I was impatient because I couldn't think of a policy right away, but when I think calmly, the minimum tax-excluded price at which the consumption tax is * A * yen at the 8% consumption tax rate is ceil (* A * / 0.08) = ceil. (12.5 * A ) Yen. The minimum tax-excluded price at 10% VAT rate is * B * Yen is ceil ( B * / 0.1) = ceil (10 * B *) Yen. The smaller one is * N *. For example, the minimum tax-excluded price at which the consumption tax is * A * yen at the 8% consumption tax rate, ceil (12.5 * A *) yen is assumed to be smaller. * N * The answer is * N * when = ceil (12.5 * A *) and * N * plus 1 and the first floor (0.1 * N *) = * B *. Since floor (0.08 * N *) may become larger than * A * in the middle of adding, -1 is output because there is no answer at that time. The same applies when the magnitude relationship is opposite. In Python, if you enclose it in int (), it becomes a floor. It's complicated! !! !! And how do you write the ceil and floor symbols in Markdown ... can anyone please tell me!

My answer

import math
A, B = map(int, input().split())
ans = -1
 
flg = True
 
if math.ceil(12.5*A) >= B*10:
    N = B*10
    while int(N*0.08) < A:
        N += 1
        if int(N*0.1) > B:
            flg = False
            break
    if flg: ans = N
 
else:
    N = math.ceil(12.5*A)
    while int(N*0.1) < B:
        N += 1
        if int(N*0.08) > A:
            flg = False
            break
    if flg: ans = N
 
print(ans)

D problem

This is because if you implement the operation of the question sentence as it is, it takes time to invert the character or add the character to the beginning, and depending on the test case, the answer can not be output within 2 seconds. When adding, the operation to move the subscript of the array that holds the string back one by one should have been done. So it should be slow.) So here while keeping whether the string is inverted now ** append ** the characters that follow the head and tail of * S * when viewed in the original orientation to separate lists (important here! Addition by append is only added to the end of the list, so processing The time is short.) Finally, I went with the strategy of paying attention to the direction and connecting and outputting.

My answer


S = input()
Q = int(input())
 
flg = "moto"
 
atama = list()
shippo = list()
 
for _ in range(Q):
    tmp = list(map(str, input().split()))
    if flg == "moto":
        if int(tmp[0]) == 1:
            flg = "hanten"
        else:
            if int(tmp[1]) == 1:
                atama.append(tmp[2])
            else:
                shippo.append(tmp[2])
    
    else:
        if int(tmp[0]) == 1:
            flg = "moto"
        else:
            if int(tmp[1]) == 1:
                shippo.append(tmp[2])
            else:
                atama.append(tmp[2])
 
if flg == "moto":
    atama = atama[::-1]
    print("".join(atama) + S + "".join(shippo))
 
else:
    shippo = shippo[::-1]
    print("".join(shippo) + S[::-1] + "".join(atama))

Impressions

That's all I have solved. From now on, I aim to learn basic algorithms such as DP and AC up to the E problem! I think he did his best for a major in biological science.

Recommended Posts

I participated in AtCoder (ABC158)
I participated in AtCoder (ABC169 edition)
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
AtCoder ABC176
AtCoder ABC177
I participated in the ISUCON10 qualifying!
Solve Atcoder ABC169 A-D in Python
I participated in PyData Tokyo Meetup # 2
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
I wanted to solve ABC159 in Python
AtCoder ABC 175 Python
Daily AtCoder # 36 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 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 # 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
Atcoder ABC115 Past Exercises
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 # 34 in Python