結果

問題 No.199 星を描こう
ユーザー n_knuun_knuu
提出日時 2015-04-29 17:05:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-09-19 04:06:56
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,768 KB
testcase_01 AC 20 ms
8,904 KB
testcase_02 AC 21 ms
8,872 KB
testcase_03 WA -
testcase_04 AC 22 ms
8,732 KB
testcase_05 WA -
testcase_06 AC 21 ms
8,872 KB
testcase_07 WA -
testcase_08 AC 21 ms
8,724 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 21 ms
8,876 KB
testcase_15 WA -
testcase_16 AC 21 ms
8,776 KB
testcase_17 AC 20 ms
8,764 KB
testcase_18 AC 21 ms
8,696 KB
testcase_19 AC 20 ms
8,852 KB
testcase_20 AC 20 ms
8,924 KB
testcase_21 WA -
testcase_22 AC 20 ms
8,880 KB
testcase_23 AC 21 ms
8,776 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 20 ms
8,920 KB
testcase_27 AC 21 ms
8,896 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)

from functools import cmp_to_key
def cmp_x(p, q):
    return p.x < p.y if p.x != q.x else p.y < q.y

def convex_hell(ps, n):
    """ P(x, y) : point P
        n : number of point
    """
    ps.sort(key=cmp_to_key(cmp_x))
    k = 0
    qs = [[] for _ in range(2*n)]
    for i in range(n):
        while k > 1 and (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0:
            k -= 1
        qs[k] = ps[i]
        k += 1
    
    t = k
    for i in range(n-2, -1, -1):
        while k > t and (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0:
            k -= 1
        qs[k] = ps[i]
        k += 1
        
    qs = qs[:-qs.count([])]
    return qs

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