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!
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")
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)
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)
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))
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