2020-03

その他

AppleScriptでPython3 command not foundが出る

brew install python3した後に、AppleScriptで以下のようなコマンドを書いた。do shell script "python3 hoge/fuga.sh"しかし、command not foundとなり実行不可。P...
AtCoder

AtCoder Beginner Contest 160の感想

ABC160に参加した。A - Coffeeそのまま実装。s = input()if s == s and s == s: print('Yes')else: print('No')B - Gol...
AtCoder

AtCoder Beginner Contest 159の感想

ABC159に参加した。A - The Number of Even Pairs偶数+偶数か、奇数+奇数の2通り。n, m = map(int, input().split())ans = n * (n - 1) // 2 + m * (m...
AtCoder

AtCoder Beginner Contest 158の感想

ABC158に参加した。A - Station and BusAのみ又はBのみの場合はNoになる。s = input()if len(list(set(s))) == 1: print('No')else: pr...
Python

Pythonで幅優先探索と深さ優先探索の実装と使い分け

木構造や迷路の探索を行う際、幅優先探索と深さ優先探索を使うことがある。以下のようなシンプルな木構造を与えられた時、各ノードを探索していくというようなシンプルな実装を考える。図はこちらのサイトで作成。幅優先探索はキューfrom collect...
Python

Pythonで逆元を使ってnCr mod 1000000007を計算

AtCoderを始めてから、1000000007で割ったあまりを求めよ、という問題を見る機会があった。直近だとAtCoder Beginner Contest 156のD問題 Bouquet。足し算、引き算、掛け算の場合は計算途中でmodを...