< uruneaさんのAI生成コード置き場

ソートいじいじ系(Codon対応)(下のコードは偏角ソート)

投稿者urunea
言語PyPy3
更新日時 (JST)2026-10-25 00:21:40
サイズ782 Byte
参照URL

日時はサーバーが記録したものです。更新すると更新日時が変わるので、不都合がある場合は新しく投稿してください。

テキストで開く
"""
lt = less than
A, Bにおいて、A<BならTrue、そうでないならFalse

ge = greater or equal
A, Bにおいて、A>=BならTrue、そうでないならFalse
"""

#↓を自由に書き換える
class K:
    x: int
    y: int
    a: int
    def __init__(self, p):
        self.x, self.y = p
        self.a = 0 if self.y > 0 or (self.y == 0 and self.x > 0) else 1
    def __lt__(self, o):
        return self.a < o.a if self.a != o.a else self.x * o.y > self.y * o.x
    def __ge__(self, o) -> bool:
        return not self.__lt__(o)

"""
使用例

N = int(input())
mem = []
bit_mem = []
for _ in range(N):
    nu = input().split()
    X, Y = int(nu[0]), int(nu[1])
    mem.append((X, Y))
    bit_mem.append((X, Y))
    bit_mem.append((-X, -Y))
    
bit_mem.sort(key=K)
"""