結果

問題 No.199 星を描こう
ユーザー n_knuun_knuu
提出日時 2015-04-29 17:56:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 11,120 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-08-28 18:38:25
合計ジャッジ時間 1,486 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,244 KB
testcase_01 AC 14 ms
8,168 KB
testcase_02 AC 15 ms
8,280 KB
testcase_03 AC 16 ms
8,172 KB
testcase_04 AC 16 ms
8,372 KB
testcase_05 AC 15 ms
8,392 KB
testcase_06 AC 15 ms
8,316 KB
testcase_07 AC 15 ms
8,348 KB
testcase_08 AC 15 ms
8,176 KB
testcase_09 AC 14 ms
8,396 KB
testcase_10 AC 14 ms
8,392 KB
testcase_11 AC 15 ms
8,216 KB
testcase_12 AC 15 ms
8,212 KB
testcase_13 AC 15 ms
8,320 KB
testcase_14 AC 14 ms
8,272 KB
testcase_15 AC 14 ms
8,276 KB
testcase_16 AC 14 ms
8,396 KB
testcase_17 AC 15 ms
8,408 KB
testcase_18 AC 14 ms
8,044 KB
testcase_19 AC 15 ms
8,260 KB
testcase_20 AC 15 ms
8,272 KB
testcase_21 AC 15 ms
8,176 KB
testcase_22 AC 15 ms
8,208 KB
testcase_23 AC 14 ms
8,272 KB
testcase_24 AC 15 ms
8,236 KB
testcase_25 AC 15 ms
8,240 KB
testcase_26 AC 15 ms
8,272 KB
testcase_27 AC 14 ms
8,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

eps = 1e-10

def add(a, b):
    return 0 if abs(a + b) < eps * (abs(a) + abs(b)) else a + b

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(add(self.x, p.x), add(self.y, p.y))

    def __sub__(self, p):
        return Point(add(self.x, -p.x), add(self.y, -p.y))

    def __mul__(self, d):
        return Point(self.x * d, self.y * d)

    def dot(self, p):
        return add(self.x * p.x, self.y * p.y)

    def det(self, p):
        return add(self.x * p.y, -self.y * p.x)

    def __str__(self):
        return "({}, {})".format(self.x, self.y)

def convex_hull(ps):
    ps = [Point(x, y) for x, y in sorted([(p.x, p.y) for p in ps])]
    upper_hull = get_bounds(ps)
    ps.reverse()
    lower_hull = get_bounds(ps)
    del upper_hull[-1]
    del lower_hull[-1]
    upper_hull.extend(lower_hull)
    return upper_hull

def get_bounds(ps):
    qs = [ps[0], ps[1]]
    for p in ps[2:]:
        while len(qs) > 1 and (qs[-1] - qs[-2]).det(p - qs[-1]) <= 0:
            del qs[-1]
        qs.append(p)
    return qs


qs = []
for i in range(5):
    x, y = map(int, input().split())
    qs.append(Point(x, y))
qs = convex_hull(qs)
print('YES' if len(qs) == 5 else 'NO')
0