結果

問題 No.199 星を描こう
ユーザー rpy3cpprpy3cpp
提出日時 2015-04-29 00:29:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 7,964 KB
最終ジャッジ日時 2023-08-28 18:37:19
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,804 KB
testcase_01 AC 15 ms
7,868 KB
testcase_02 AC 14 ms
7,792 KB
testcase_03 AC 15 ms
7,856 KB
testcase_04 AC 14 ms
7,872 KB
testcase_05 AC 15 ms
7,796 KB
testcase_06 AC 14 ms
7,800 KB
testcase_07 AC 15 ms
7,840 KB
testcase_08 AC 15 ms
7,860 KB
testcase_09 AC 15 ms
7,796 KB
testcase_10 AC 14 ms
7,856 KB
testcase_11 AC 14 ms
7,844 KB
testcase_12 AC 14 ms
7,868 KB
testcase_13 AC 14 ms
7,792 KB
testcase_14 AC 15 ms
7,904 KB
testcase_15 AC 14 ms
7,788 KB
testcase_16 AC 15 ms
7,784 KB
testcase_17 AC 14 ms
7,964 KB
testcase_18 AC 15 ms
7,804 KB
testcase_19 AC 14 ms
7,904 KB
testcase_20 AC 14 ms
7,832 KB
testcase_21 AC 14 ms
7,868 KB
testcase_22 AC 14 ms
7,952 KB
testcase_23 AC 15 ms
7,936 KB
testcase_24 AC 14 ms
7,848 KB
testcase_25 AC 14 ms
7,808 KB
testcase_26 AC 14 ms
7,868 KB
testcase_27 AC 14 ms
7,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def convex_hull(points):
    '''二次元平面上の点のリスト points の凸包を返す。Andrew のアルゴリズムを使用。
    引数:
        points = [(x0, y0), (x1, y1),...] 点のリスト
        同じ点は含まない(全て異なる点である)とする。
    返り値:
        convex_hull = [(xi, yi), (xj, yj),...] 点のリスト。時計回りに並んでいる。
    '''
    points.sort()
    upper_bounds = get_bounds(points)
    points.reverse()
    lower_bounds = get_bounds(points)
    del upper_bounds[-1]
    del lower_bounds[-1]
    upper_bounds.extend(lower_bounds)
    return upper_bounds


def get_bounds(points):
    bounds = [points[0], points[1]]
    for xi, yi in points[2:]:
        while len(bounds) > 1 and not is_convex(bounds, xi, yi):
            del bounds[-1]
        bounds.append((xi, yi))
    return bounds


def is_convex(bounds, x2, y2):
    x1, y1 = bounds[-1]
    x0, y0 = bounds[-2]
    return (x1 - x0) * (y2 - y1) < (y1 - y0) * (x2 - x1)


def read_data():
    points = []
    for i in range(5):
        x, y = map(int, input().split())
        points.append((x, y))
    return points

def is_star(points):
    return len(convex_hull(points)) == 5

if __name__ == "__main__":
    points = read_data()
    if is_star(points):
        print('YES')
    else:
        print('NO')
0