0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC389をPythonで(A~D)

Posted at

トヨタ自動車プログラミングコンテスト2025(AtCoder Beginner Contest 389)の解答等の速報的まとめ

A問題

入力をeval関数で計算する。ただし$x$は$*$に変換する必要がある。

A
print(eval(input().replace(*"x*")))

B問題

実際に入力された値になるまで足していく。

B
x = int(input())

a = 1
n = 1
while a < x:
    n += 1
    a *= n

print(n)

C問題

累積和の考え方を利用する。
$i$匹目の蛇のしっぽまでの長さを計算して、(求めたい蛇の順番+抜けた蛇の匹数)の値から(抜けた蛇の匹数)の値を引いたものが答えとなる

C
lst = [0]
head = 0

for _ in range(int(input())):
    com = list(input().split())
    if com[0] == "1":
        l = int(com[1])
        lst.append(l + lst[-1])
    elif com[0] == "2":
        head += 1
    else:
        k = int(com[1])
        print(lst[k - 1 + head] - lst[head])

D問題

円を4分割し、各扇型に含まれる正方形の数を尺取り法で計算する。
ただし、以下のやり方は中心を含む正方形を数えないため1足す必要がある。

D
r = int(input())

ans = 0
h = r + 2
line = 0
for i in range(r + 1):
    while h > 0 and (h + 0.5) ** 2 + (i + 0.5) ** 2 > r ** 2:
        h -= 1
    ans += h
    if i == 0:
        line = h

print(ans * 4 + 1)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?