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?

[ABC460] ABC 460(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

0
Posted at

[ABC460] ABC 460(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

A問題

A.py
"""
<方針>
- まあ,愚直に回数をカウントしましょうか.
"""
# 入力
N, M = map(int, input().split())

cnt = 0
while (M != 0):
  # 余りを渡す
  M = N%M
  cnt += 1

# 出力
print(cnt)

B問題

  • 中心を結ぶ線 d が半径の差 diffR 以上で,半径の和 sumR 以下だったら良さそう.
B.py
"""
<方針>
- 中心を結ぶ線 `d` が半径の差 `diffR` 以上で,半径の和 `sumR` 以下だったら良さそう.
"""
for _ in range(int(input())):
  X1, Y1, R1, X2, Y2, R2 = map(int, input().split())
  dSquare = (X1-X2)**2 + (Y1-Y2)**2 # dの二乗
  diffRSquare = (R1 - R2)**2 # diffRの二乗
  sumRSquare = (R1 + R2)**2 # sumRの二乗
  if(diffRSquare <= dSquare <= sumRSquare):
    print("Yes")
  else:
    print("No")

C問題

方針

  • ソートして貪欲にやればいけそう.

前提

  • C問題あたりで,TLEになる人は,制約条件を見る癖をつけよう.
  • AB問題では,基本的に制約条件を見ずにやっても解ける.
  • しかし,C問題以降では,制約条件を見ないと必ずTLEすると思っても良い.
  • 詳しい話は私の352回の記事C問題の解説に記したので,是非参照してほしい.
C.py
"""
<方針>
- ソートして貪欲にやればいけそう.
"""
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.sort()
B.sort()

indB = 0
ans = 0
for a in A:
  if(indB == M):
    break # index out of range 対策
  if(B[indB] <= 2*a):
    ans += 1
    indB += 1 # 次のネタへ
    

print(ans)

補足

関係するリンク(参考文献など)

筆者について

その他

  • 間違いを含んでいる可能性があります.
  • 方針と言いつつ,方針ではない感想などを書いている可能性があります.
  • A問題から解説がだんだん省略されます.
  • コードに書かれている解説の文言と,その上に書いてある解説の文言を変えている場合があります.

最後に一言

  • LLMとシンボリックリンクがわからない...
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?