ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 25315 |
문제명 | N수매화검법 |
레벨 | 골드 2 |
분류 |
기하, 선분교차 |
시간복잡도 | O(n^2) |
인풋사이즈 | n<=2500 |
사용한 언어 | Python |
제출기록 | 30840KB / 1816ms |
최고기록 | 1816ms |
해결날짜 | 2022/08/18 |
(((ay2 - ay1) * (bx1 - ax2) > (ax2 - ax1) * (by1 - ay2)) !=
((ay2 - ay1) * (bx2 - ax2) > (ax2 - ax1) * (by2 - ay2))) and
(((by2 - by1) * (ax1 - bx2) > (bx2 - bx1) * (ay1 - by2)) !=
((by2 - by1) * (ax2 - bx2) > (bx2 - bx1) * (ay2 - by2)))
"""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()