Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions libs/dis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import Tuple


def euclid_dis(x1: int, y1: int, x2: int, y2: int) -> int:
"""
ユークリッド距離を計算します

注意:
この関数はsqrtを取りません(主に少数誤差用)
sqrtを取りたい場合は、自分で計算してください
"""

return ((x1 - x2) ** 2) + ((y1 - y2) ** 2)


def manhattan_dis(x1: int, y1: int, x2: int, y2: int) -> int:
"""
マンハッタン距離を計算します
"""

return abs(x1 - x2) + abs(y1 - y2)


def manhattan_45turn(x: int, y: int) -> Tuple[int]:
"""
座標を45度回転します
回転すると、マンハッタン距離が、チェビシェフ距離になるので、距離の最大値などが簡単に求められます
"""

res_x = x - y
res_y = x + y

return res_x, res_y


def chebyshev_dis(x1: int, y1: int, x2: int, y2: int) -> int:
"""
チェビシェフ距離を計算します
"""

return max(abs(x1 - x2), abs(y1 - y2))
8 changes: 3 additions & 5 deletions libs/math_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ def calc_divisors(N):
計算量は、√Nです
約数は昇順に並んでいます
"""
import heapq

result = []

for i in range(1, N + 1):
Expand All @@ -80,11 +78,11 @@ def calc_divisors(N):
if N % i != 0:
continue

heapq.heappush(result, i)
result.append(i)
if N // i != i:
heapq.heappush(result, N // i)
result.append(N // i)

return result
return sorted(result)


def factorization(n):
Expand Down
27 changes: 14 additions & 13 deletions merge_file.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ echo "新しいmain.py作成完了"
# テンプレ
# /bin/cat python/<filename>.py >> code/main.py

cat libs/import.py >> code/main.py
cat libs/math_func.py >> code/main.py
cat libs/array_create.py >> code/main.py
cat libs/binary_search.py >> code/main.py
cat libs/modint.py >> code/main.py
cat libs/standard_input.py >> code/main.py
cat libs/yn_func.py >> code/main.py
cat libs/grid.py >> code/main.py
cat libs/memo.py >> code/main.py
cat libs/grath.py >> code/main.py
cat libs/unionfind.py >> code/main.py
cat libs/trie.py >> code/main.py
cat libs/utils.py >> code/main.py
cat libs/import.py >>code/main.py
cat libs/math_func.py >>code/main.py
cat libs/array_create.py >>code/main.py
cat libs/binary_search.py >>code/main.py
cat libs/modint.py >>code/main.py
cat libs/standard_input.py >>code/main.py
cat libs/yn_func.py >>code/main.py
cat libs/grid.py >>code/main.py
cat libs/memo.py >>code/main.py
cat libs/grath.py >>code/main.py
cat libs/unionfind.py >>code/main.py
cat libs/trie.py >>code/main.py
cat libs/dis.py >>code/main.py
cat libs/utils.py >>code/main.py

echo "作業完了"

Expand Down