목차

N수매화검법

ps
링크acmicpc.net/…
출처BOJ
문제 번호25315
문제명N수매화검법
레벨골드 2
분류

기하, 선분교차

시간복잡도O(n^2)
인풋사이즈n<=2500
사용한 언어Python
제출기록30840KB / 1816ms
최고기록1816ms
해결날짜2022/08/18

풀이

코드

"""Solution code for "BOJ 25315. N수매화검법".

- Problem link: https://www.acmicpc.net/problem/25315
- Solution link: http://www.teferi.net/ps/problems/boj/25315

Tags: [Geometry] [Greedy]
"""

import sys


def main():
    N = int(sys.stdin.readline())
    line_segments = []
    for _ in range(N):
        sx, sy, ex, ey, w = [int(x) for x in sys.stdin.readline().split()]
        line_segments.append((w, sx, sy, ex, ey, ex - sx, ey - sy))
    line_segments.sort(reverse=True)
    answer = 0
    for _ in range(N):
        w, ax1, ay1, ax2, ay2, axdiff, aydiff = line_segments.pop()
        for _, bx1, by1, bx2, by2, bxdiff, bydiff in line_segments:
            if (((aydiff * (bx1 - ax2) > axdiff * (by1 - ay2)) !=
                 (aydiff * (bx2 - ax2) > axdiff * (by2 - ay2))) and
                ((bydiff * (ax1 - bx2) > bxdiff * (ay1 - by2)) !=
                 (bydiff * (ax2 - bx2) > bxdiff * (ay2 - by2)))):
                answer += w
        answer += w

    print(answer)


if __name__ == '__main__':
    main()